zoukankan      html  css  js  c++  java
  • bing map 画圆,其他百度地图、谷歌地图、搜搜地图、搜狗地图等稍微修改即可

      最近需要在bing 地图上画圆,因为bing 地图没有直接提供画圆的API,画起来比较麻烦,经过在网上的查找终于找到了画圆的方法。下面的代码是我整理过的代码,其中画圆函数来至网络。因为画圆比较困难,所以分享给大家,让大家也少走弯路。

      如果你使用的是其他地图,例如百度地图、谷歌地图、搜搜地图、搜狗地图等,适当修改提供的api接口即可实现。如果需要进行地图的定制开发,请发送站内信给我。

      上代码,呵呵。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
        <head>
            <title>bing map画圆</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <script type="text/javascript"
                src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=zh-cn"></script>
            <script type="text/javascript">
             var map     = null;
             function GetMap()
             {
                map = new VEMap('myMap');
                map.LoadMap();
                map.SetZoomLevel(14);
                var latLon=new VELatLong(34.79248399030799,113.69712352752688);
                //设置地图中心点
                map.SetCenter(latLon);
                map.SetMouseWheelZoomToCenter(false);
                //画圆,以地图中心latLon为圆心,半径为1km 画圆
                drawCircle(latLon,1);
             }
             //画圆函数 origin 圆心,radius 半径 单位km
            function drawCircle(origin, radius) {
                var earthRadius = 6371;
                //圆心纬度
                var lat = (origin.Latitude * Math.PI) / 180;
                //圆心经度
                var lon = (origin.Longitude * Math.PI) / 180;
                var d = parseFloat(radius) / earthRadius;
                var points = new Array();
                for (i = 0; i <= 360; i++) {
                    var point = new VELatLong(0, 0);
                    var bearing = i * Math.PI / 180; 
                    point.Latitude = Math.asin(Math.sin(lat) * Math.cos(d) + Math.cos(lat) * Math.sin(d) * Math.cos(bearing));
                    point.Longitude = ((lon + Math.atan2(Math.sin(bearing) * Math.sin(d) * Math.cos(lat), Math.cos(d) - Math.sin(lat) * Math.sin(point.Latitude))) * 180) / Math.PI;
                    point.Latitude = (point.Latitude * 180) / Math.PI;
                    points.push(point);
                }
                var circle = new VEShape(VEShapeType.Polygon, points);
                //设置无边缘
                circle.SetLineColor(new VEColor(255, 0, 0, 0));
                circle.HideIcon();
                map.AddShape(circle);
            }
          </script>
        </head>
        <body onload="GetMap();">
            <div id='myMap'
                style="position: relative;  400px; height: 400px;"></div>
        </body>
    </html>
  • 相关阅读:
    实现qsort(和qsort差一个数量级啊,伤自尊了)
    广度优先遍历目录(Windows平台、C++)
    在CentOS上以源码编译的方式安装Greenplum数据库
    Java泛型函数的运行时类型检查的问题
    Android代码的几点小技巧
    关于矢量图片资源向后兼容:CompatVectorFromResourcesEnabled标志的使用
    指定Android Studio编译工程时的源文件编码
    安卓日历同步的一些要点
    Android Studio编译错误:Unexpected lock protocol found in lock file. Expected 3, found 0.
    系统信息命令
  • 原文地址:https://www.cnblogs.com/myzhijie/p/2969940.html
Copyright © 2011-2022 走看看