Export (0) Print
Expand All

VEMap.GetHeading Method

You are not viewing the latest version of the AJAX control. Bing Maps AJAX V7 is the recommended JavaScript control for Bing Maps. If you need this documentation, it is available in as a CHM or PDF download.

In 3D mode, returns a double that represents the compass heading of the current map view.


VEMap.GetHeading();

A double that represents the compass heading, where 0 is true north and 180 is true south.

The VEMap.GetAltitude Method, the GetHeading method and the VEMap.GetPitch Method return values only when the map mode (VEMapMode Enumeration) is set to Mode3D and the current map view is completely loaded. To be sure that the map view is completely loaded, you can use the VEMap.onendpan Event.

<!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=6.3"></script>

      <script type="text/javascript">
         var map = null;
         var center = new VELatLong(33.338550,-118.424636);
         var initView = new VEMapViewSpecification(center, 1, 900000, -90, 0);

         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap();

            map.SetMapMode(VEMapMode.Mode3D);
            map.SetMapStyle(VEMapStyle.Aerial);
            map.SetMapView(initView);
         }   
    
         function SetHeading()
         {
            if (document.getElementById('txtHdg').value != null && document.getElementById('txtHdg').value <= 360 && document.getElementById('txtHdg').value > -1)
            {
               map.SetHeading(document.getElementById('txtHdg').value);
               var heading = map.GetHeading();
               alert("The map heading is " + heading + " degrees.");
            }
            else
            {
               alert("Please enter a value between 0 and 360.");
            }
         }

      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position: relative; width: 400px; height: 400px;">
      </div>
      <input id="sethdg" type="button" value="Set a Heading Value" name="sethdg" onclick="SetHeading();">
      <input id="txtHdg" type="text" name="txtHdg" maxlength="3" value="270">
   </body>
</html>

Show:
© 2014 Microsoft