【发布时间】:2019-10-30 07:42:29
【问题描述】:
我有一个包含多个地址的数据库,我正在尝试使用 Google Maps API 标记所有地址。我以前使用过此代码,但它一次只允许我使用一个位置。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps Geocoding Demo 1</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 400px; height: 300px;"></div>
<script type="text/javascript">
var address = 'London, UK';
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.TERRAIN,
zoom: 6
});
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': address
},
function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
map.setCenter(results[0].geometry.location);
}
});
</script>
</body>
</html>
【问题讨论】:
-
有多少个地址?您可以将坐标存储在数据库中吗?您是否搜索过您的问题的重复项?
-
我有大约 20 个左右,我只能使用城市、邮政编码和地址。前段时间我在上面找到了这段代码 sn-p,它可以满足我的需求,但我需要使用多个地址。
-
20 是可行的,但您需要处理查询速率限制。这里有几个重复的,我会在时间允许的时候尝试挖掘一个。
-
好的,非常感谢!
-
有没有办法通过支付更多来提高查询速率限制,或者如果我获得更多地址,我必须将请求分成许多小请求?钱不是问题。
标签: javascript google-maps google-maps-api-3