gpt4 book ai didi

javascript - 无法显示带有基于邮政编码的标记的 Google map

转载 作者:行者123 更新时间:2023-11-28 08:27:39 25 4
gpt4 key购买 nike

我正在尝试显示带有基于邮政编码的标记的 Google map 。我已经在 latlng 坐标上转换了邮政编码,但问题是 map 根本不显示。

这是我尝试这样做的方法:

  function initialize() {
var lat = '';
var lng = '';
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': 94301}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(lat, lng)
};
var map = new google.maps.Map(document.getElementById("gmap"), myOptions);
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
alert('111');
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
google.maps.event.addDomListener(window, 'load', initialize);
}

alert('111')都没有出现。

我做错了什么?

谢谢

最佳答案

你的问题就在这里,你初始化函数中调用初始化函数!

function initialize() {
...
google.maps.event.addDomListener(window, 'load', initialize);
}

将最后一行移出该函数,我认为您将开始看到一些结果。

function initialize() {
...
}
google.maps.event.addDomListener(window, 'load', initialize);

关于javascript - 无法显示带有基于邮政编码的标记的 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22225938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com