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);


Parameter Description


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


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.


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" "">
      <title>VEMap.Geocode Method</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <script type="text/javascript" src=""></script>

      <script type="text/javascript">
         var map     = null;
         function GetMap()
            map = new VEMap('myMap');

         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';


   <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()"/>