how to draw path or line two pushpins in bing map?

老子叫甜甜 提交于 2020-02-02 14:07:00

问题


Hi I want draw line or paths between two pushpins in bing map using Javascript SDK. This is a google map example I want similar like this.


回答1:


Here you go, you need to have your bing map credentials.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title></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=7.0"></script>

      <script type="text/javascript">

         var map = null;
         function GetMap() {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Map Credentials"}); 

            var loc1 = new Microsoft.Maps.Location(33.719753, -117.98925);
            var loc2 = new Microsoft.Maps.Location(33.993065, -117.918015);
            var loc3 = new Microsoft.Maps.Location(34.13095, -118.25497);

            // Add a pin to the map
            var pin1 = new Microsoft.Maps.Pushpin(loc1); 
            var pin2 = new Microsoft.Maps.Pushpin(loc2); 
            var pin3 = new Microsoft.Maps.Pushpin(loc3); 

            // Create a polyline
            var lineVertices = new Array(loc1, loc2, loc3);
            var line = new Microsoft.Maps.Polyline(lineVertices);

            map.setView({center:loc2, zoom: 9} );

            map.entities.push(line);
            map.entities.push(pin1);
            map.entities.push(pin2);
            map.entities.push(pin3);

         }
      </script>
   </head>
   <body onload="GetMap();">
      <div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>
   </body>
</html>


来源:https://stackoverflow.com/questions/20795475/how-to-draw-path-or-line-two-pushpins-in-bing-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!