我正在处理JavaScript
。我有像["Chennai","Hyderabad","Bangalore",....]
这样的数组格式,我想找到latitude and longitude
。
据我所知,我可以使用geocode
一次找到一个地方的详细信息。但我想找到大量的地方详情。为此,我读了Google batch request
(link)概念,我不明白。
我可以逐个发出API请求,但这不是一个好习惯。即使我按照相同的方式,我也会从Google获得限制错误。
任何人都可以帮助我,我怎样才能找到latitude and longitude
详细信息。
如果有人想要投票,请告诉我原因。
感谢。
答案 0 :(得分:1)
使用Geocoder
:
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: address },
function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
console.log('lng: ' + location. getLng() + ', lat: ' + location.getLat());
}
});
请注意,您无法使用地理编码器API执行批量请求。但您可以使用方向api对最多8个地址进行地理编码。在商务舱中,它最多允许24个地址。了解它: https://developers.google.com/maps/documentation/javascript/directions