Bing Maps Ajax API - get location from address

主宰稳场 提交于 2019-12-05 23:25:31

问题


I'm using Microsoft.Maps API (AJAX control v. 7). I want to display pin for an address. When I use:

var loc = new Microsoft.Maps.Location(47.592, -122.332);
var pOptions = {icon: 'img/ICN_Bullet_Blue_25x38.gif', text: '1'};
var pin = new Microsoft.Maps.Pushpin(loc, pOptions);

It's working fine. How can I get latitude and longitude from address, so I will later use it for pin location ?


回答1:


Bing Maps includes geocoding support (finding location by addresses).

You have two options for this:

  • Use the REST api directly. http://msdn.microsoft.com/en-us/library/ff701714.aspx

In that page you can find plenty of examples. You make a REST HTTP request and obtain a JSON that includes the geocoded coordinates.

  • Use the Microsoft.Maps.Search module. http://msdn.microsoft.com/en-us/library/hh868060.aspx

You just load the module and then do something like:

var search = new Microsoft.Maps.Search.SearchManager(map);

search.geocode({where:"some address...", count:10, callback:geocodeCallback});

and then, in your callback just handle the results:

function geocodeCallback(geocodeResult, userData)
{
    var location = geocodeResult.results[0].location;
}


来源:https://stackoverflow.com/questions/17867959/bing-maps-ajax-api-get-location-from-address

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!