我的脚本有问题。 我有一切正确设置,但地理编码不起作用,当我在我创建的形式输入一个城市的名称,然后我点击“geocoder”它没有任何反应。 这是我的代码:地理编码谷歌地图不起作用
变量:
var geocoder;
var map;
var markers = new Array();
var i = 0;
天气预报脚本:
<!-- GEOCODER -->
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
document.getElementById('lat').value = results[0].geometry.location.lat();
document.getElementById('lng').value = results[0].geometry.location.lng();
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
markers.push(marker);
if(markers.length > 1)
markers[(i-1)].setMap(null);
i++;
} else {
alert("Le geocodage n\'a pu etre effectue pour la raison suivante: " + status);
}
<!-- GEOCODER -->
表:
<div>
Adresse : <input id="address" type="text" value="paris">
<input type="button" value="Geocoder" onsubmit="codeAddress()">
</div>
的完整代码(仅HTML):http://jsfiddle.net/hCmQb/
你拨弄不起作用。在网页加载时,超过10个位置的地理编码会遇到配额和速率限制,需要非常长的时间并且不鼓励,将位置进行离线编码,并使用生成的坐标来显示标记。 – geocodezip 2013-03-03 16:32:45