Bing Maps Ajax API-从地址获取位置 [英] Bing Maps Ajax API - get location from address

查看:54
本文介绍了Bing Maps Ajax API-从地址获取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft.Maps API(AJAX控件第7版). 我想显示一个地址的图钉. 当我使用时:

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 ?

推荐答案

Bing Maps支持地理编码(按地址查找位置).

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

您有两种选择:

在该页面中,您可以找到许多示例.您发出一个REST HTTP请求,并获得一个包含地理编码坐标的JSON.

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

您只需加载模块,然后执行以下操作:

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

这篇关于Bing Maps Ajax API-从地址获取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆