Export (0) Print
Expand All

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

Finds a geographic location based on a specified address or place name string as well as other geocoding options.

VEMap.Geocode(query, callback, options);

Parameters

Parameter Description

query

The query string to match to a location on the map.

callback

The name of the function that the server calls with the geocode results. If this parameter is not null and useDefaultDisambiguation is true, this function is not called until the user has made a disambiguation choice.

options

A VEGeocodeOptions Class object specifying additional options.

This method does not return a value. The function defined by the callback parameter receives the following arguments, in the order shown, from the server:

  • A VEShapeLayer Class object.

  • An array of VEFindResult Class objects. For a Geocode call, this argument will always be null.

  • An array of VEPlace Class objects.

  • A Boolean value indicating whether there are more results after the current set.

  • A String containing a possible error message.

The Geocode method only returns results with high match confidence to the callback function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title>VEMap.Geocode Method</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;
 
         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap();
            
         }


         function ClickGeocode()
         {

            map.Geocode(document.getElementById('txtQuery').value, findCallback);
         }


         function findCallback(layer, findResults, placeResults, moreResults, error)
         {
            var s='';
            for (var i=0; i < placeResults.length; ++i)
            { 
               s += 'Name: ' + placeResults[i].Name + '\n'; s+= 'LatLong: ' + placeResults[i].LatLong + '\n'; s+= 'MatchCode: ' + placeResults[i].MatchCode+ '\n'; s+= 'MatchConfidence: ' + placeResults[i].MatchConfidence+ '\n'; s += '\n\n';
            }

            alert(s);
         }


      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:600px; height:400px;"></div>
      <input id="txtQuery" type="text" value="Portland"/>
      <input type="button" value="Geocode" onclick="ClickGeocode()"/>
   </body>
</html>

Show:
© 2014 Microsoft