Search code examples
c#windows-store-apps

Search a location by name on Bing Map Windows Store App C#


How can I search a location to get the longitude and latitude by some name e.g: New York? I am using Bing Map SDK of Microsoft.


Solution

  • A city I do not believe can be tied to one specific latitude and longitude as it covers a big span of area. However, using the Search Manager Class of the Bing Map SDK, you can enter an address in New York per your example to GeoCode and get the the latitude and longitude.

    From the msdn class page:

    // Set the address string to geocode
    Bing.Maps.Search.GeocodeRequestOptions requestOptions = new Bing.Maps.Search.GeocodeRequestOptions("1 Microsoft Way, Redmond, WA");
    
    // Make the geocode request 
    Bing.Maps.Search.SearchManager searchManager = myMap.SearchManager;
    Bing.Maps.Search.LocationDataResponse response = await searchManager.GeocodeAsync(requestOptions);
    

    Hope this helps