Export (0) Print
Expand All

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

Performs a search based on a given query and options.

VEMap.Search(query, callback, options);

Parameters

Parameter Description

query

The string to use in the search.

callback

The name of the function that the server calls with the search results.

options

A VESearchOptions 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:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title>VEMap.Search 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 ClickSearch()
         {
            map.Search(document.getElementById('txtQuery').value, findCallback);
         }


         function findCallback(layer, findResults, placeResults, moreResults, error)
         {
            var s='';
            if (placeResults != null)
            { 
               s += 'Where Results:\n'
               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';
               }
            } 
     
            if (findResults != null)
            { 
               s += 'What Results:\n'
               for (var i=0; i < findResults.length; ++i)
               { 
                  s += 'Name: ' + findResults[i].Name + '\n'; s+= 'Description: ' + findResults[i].Description + '\n'; s+= 'Phone: ' + findResults[i].Phone + '\n'; s+= 'LatLong: ' + findResults[i].LatLong + '\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="coffee in Seattle"/>
      <input type="button" value="Search" onclick="ClickSearch()"/>
   </body>
</html>

Show:
© 2014 Microsoft