【发布时间】:2014-04-15 06:49:17
【问题描述】:
您好,我收到地理编码器未定义错误。 我试图在页面加载时显示谷歌地图。 下面是我的代码
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
$(document).ready(function(){
var address = document.getElementById('shipAddress').value;
//alert(address);
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
});
google.maps.event.addDomListener(window, 'load', initialize);
任何帮助将不胜感激!!!
【问题讨论】:
标签: javascript google-maps google-maps-api-3 map