我想使用谷歌地理编码via HTTP在我的 AJAX Web 应用程序中将城市名称转换为经度和纬度的功能。
但是,HTTP 地理编码器功能似乎不存在回调函数
http://code.google.com/apis/maps/documentation/geocoding/index.html http://code.google.com/apis/maps/documentation/geocoding/index.html
是真的吗,不存在回调函数吗?
因为如果这是真的,那么本质上意味着通过 HTTP api 进行的 Google 地理编码在与 AJAX 一起使用时是无用的,因为 JavaScript 会抛出跨域异常错误。
关于如何在 JavaScript 中的 AJAX Web 应用程序中通过 HTTP api 使用地理编码,有什么想法吗?
Note: I do not想要使用完整的 Google Maps API,下载量约为 200kb(即 GClientGeocoder)。我想使用 HTTP api b/c,因为它具有超快的响应能力,并且不需要我的网络用户下载庞大的、完整的交互式谷歌地图 api。
E.g.
{API KEY}& q={城市,州}& CALLBACK=????
Thanks
这是使用 Google 地图地理编码器的示例。地理编码器函数 getLocation 将回调函数作为第二个参数。
function findAddress(street, city, state, zip) {
var address = [
street,
city.toLowerCase(),
state.toLowerCase(),
zip
].join(', ');
if (!geocoder) {
geocoder = new GClientGeocoder();
}
if (geocoder) {
geocoder.getLocations(
address,
function(result) {
var dialog, len, point;
if (result.Status.code != G_GEO_SUCCESS) {
alert("Error: "+result.Status.code)
} else {
len = result.Placemark.length;
if (len > 1) {
alert("Multiple matches were found. I'll leave it as an exercise to handle this condition");
} else {
point = new GLatLng(
result.Placemark[0].Point.coordinates[1],
result.Placemark[0].Point.coordinates[0]
);
}
}
}
);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)