VEMap.LatLongToPixel 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.

Converts VELatLong Class objects (latitude/longitude pair) to VEPixel Class objects.

VEMap.LatLongToPixel(latLongArray, zoomLevel, callback);

Parameters

Parameter Description

latLongArray

A VELatLong object or an array of VELatLong objects. Required. If an array is passed, the callback parameter must be specified.

zoomLevel

The zoom level at which the VELatLong objects are converted to VEPixel objects. Optional. If this parameter is not supplied, the current zoom level is used.

callback

The name of the function called with the array of corresponding VEPixel objects. Optional.

Return Value

If the callback parameter is not supplied, the LatLongToPixel method returns a VEPixel object corresponding to the VELatLong object specified in the latLongArray parameter.

If the callback parameter is supplied, the specified callback function must accept an array of VEPixel objects.

Remarks

To get the latitude and longitude of a point on the map, use the VEMap.PixelToLatLong Method.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title>VEMap.LatLongToPixel()</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></script>

      <script type="text/javascript">
         var map = null;

         function GetMap()
         {
            map = new VEMap('myMap');
         
            map.LoadMap(new VELatLong(47.62165, -122.3492), 18);

         }
            
         function GetPixel()
         {
            var info = "";

            // Get pixel info about center of the map
            var pixel = map.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());

            info += "Map center pixel coordinates are : (" + pixel.x + ", " + pixel.y + ")\n\n";

            alert(info);
            
            
         }

      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:600px; height:400px;"></div>
      <input id="getpixel" type="button" value="Get the pixel of the center of the map" name="getpixel" onclick="GetPixel();">
   </body>
</html>

See Also

Reference

VEBirdseyeScene.LatLongToPixel Method