我在我的网站上创建了一张地图。用户可以添加多个标记。在另一页上,我创建了对这些标记的调用。这是一个字符串:
的字符串 ' [{" LAT":" 40.7181193798"" LNG":" -84.4847297668""标签& #34;:" A"},{" LAT":" 40.9530752681"" LNG":" -83.9779055864& #34;"标签":" A"}]'
我发送请求
" http://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "" + long +"& sensor = true&#34 ;;
并获得JSON,但它可以在1个位置工作,如果我有很多地址要发送大量请求,这对我很不利,我试过
但它不起作用。提前谢谢。
答案 0 :(得分:1)
您希望实现的目标我很确定无法实现 - 您需要为每个地址拨打一个电话。
也许您可以从GMapsAPI切换到其他一些服务,允许您解码多个地址,如:
或者您也可以使用以下代码切换到 javascript GApi库:
var locations = [
[], // your location 1 coordinates
[], // your location 2 coordinates
[] // your location 3 coordinates
];
var geocoder = new google.maps.Geocoder();
for (i = 0; i < locations.length; i++) {
geocodeAddress(locations[i]);
}
function geocodeAddress(location) {
geocoder.geocode({
'address': location
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(result)
}
});
}
注意: javascript库也只是制作json请求,就像你上面的网址一样!
希望这有助于:)