none
Code migration bing maps v6.3 to v8 RRS feed

  • Question

  • Hi everyone! some years ago i built this script to draw a square on an map. Unfortunately this script doesn't work because of bing maps version change. 

    I try to update this script following the migration guide, but i can't get it to work. 

    I post the code below, i'm very happy if someone can help me to make this script work.

    Thanks


    <html>
       <head>
          <title>Tile Location</title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
          <script type="text/javascript"  src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"> </script>
          <script type="text/javascript">
          var map = null;
          var points = new Array(
             new VELatLong(45.1986454128372, 7.94925604120791, 0, VEAltitudeMode. RelativeToGround), //SW Corner
             new VELatLong(45.217570112056, 7.94464627954194, 0, VEAltitudeMode. RelativeToGround), //NW Corner
             new VELatLong(45.217570112056, 7.97009142585743, 0, VEAltitudeMode. RelativeToGround), //NE Corner
             new VELatLong(45.1986454128372, 7.97469586926546, 0, VEAltitudeMode. RelativeToGround) //SE Corner
          );

          function GetMap()
          {
             map = new VEMap('myMap');
             map.LoadMap();
             var myPolygon = new VEShape(VEShapeType.Polygon, points);
             map.AddShape(myPolygon);
             myPolygon.HideIcon();
             myPolygon.SetFillColor(new VEColor(0,0,0,0));
             }  
          
          </script>
       </head>
       <body onload="GetMap();">
          <div id='myMap' style="; width:1152px; height:864px;"></div>
       </body>
    </html>


    Wednesday, November 29, 2017 9:26 AM

Answers

  • Here you go. Note that you need a Bing Maps key to use the Bing Maps API's, this was a requirement with V6 as well, but a bug in that control did not enforce it. You can create a basic/public website key here:  

    https://www.bingmapsportal.com/

    <!DOCTYPE html>
    <html>
       <head>
          <title>Tile Location</title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
          <script type="text/javascript">
          var map = null;      
    
          function GetMap()
          {
    		 //5 or 6 decimal places for coordinates is more than enough, anymore are insignificant.
    		  var points = [
    			 new Microsoft.Maps.Location(45.19865, 7.94926), //SW Corner
    			 new Microsoft.Maps.Location(45.21757, 7.94465), //NW Corner
    			 new Microsoft.Maps.Location(45.21757, 7.97009), //NE Corner
    			 new Microsoft.Maps.Location(45.19865, 7.97470) //SE Corner
    		  ];
    	  
    		//Load the map.
             map = new Microsoft.Maps.Map('#myMap', {
    			credentials: 'YOUR_BING_MAPS_KEY',	//You need a Bing Maps key to use any of the Bing Maps API's. Get one at https://www.bingmapsportal.com/
    			bounds: Microsoft.Maps.LocationRect.fromLocations(points)	//Your code didn't set the map view, so you would have to go searching to find your square.
    		 });
    		 
             var myPolygon = new Microsoft.Maps.Polygon(points, {
    			fillColor: 'transparent'
    		 });
    		 
             map.entities.push(myPolygon);
    	  } 
          </script> 
    	  <script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
       </head>
       <body>
          <div id='myMap' style=";width:1152px; height:864px;"></div>
       </body>
    </html> 
    


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, November 29, 2017 6:22 PM
    • Marked as answer by GabryDagostino Wednesday, November 29, 2017 7:02 PM
    Wednesday, November 29, 2017 6:21 PM