我的腳本有問題。 我有一切正確設置,但地理編碼不起作用,當我在我創建的形式輸入一個城市的名稱,然後我點擊「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