0
我修改的JavaScript從https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple到谷歌地圖Apiv3 - 地理編碼函數來獲取緯度經度不工作
var geocoder;
var postalArr = [];
postalArr.push(249586);
postalArr.push(266751);
var map;
function initialize(){
var myLatlng = new google.maps.LatLng(1.3667, 103.7500);
var myOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
if (postalArr) {
for (var i = 0; i < postalArr.length; i++) {
codeAddress(postalArr[i]);
}
}
map = new google.maps.Map(document.getElementById('map_canvas'),
myOptions);
}
function codeAddress(postal) {
geocoder.geocode({ 'postal': postal}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var markerE = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
腳本去內的for循環,但不運行codeAddress功能。 我不知道爲什麼。
嗯,我仍然沒有看到銷。 249586是新加坡的郵政編碼,所以我做了'geocoder.geocode({'address':postal +',Singapore'}'但谷歌的例子能夠找到基於6個數字的地址,所以我不確定是否是問題。感謝您指出地理編碼器的初始化:) – consprice 2012-07-10 03:12:32
您是否已將數字更改回新加坡郵政編碼?嘗試[** this update **](http://jsfiddle.net/yV6xv/148/) – 2012-07-10 03:14:48
語法錯誤。現在正在工作。謝謝您的幫助:) – consprice 2012-07-10 03:21:20