1
試圖讓我的SetCenter功能工作,但沒有。谷歌地圖SetCenter功能拒絕工作
下面是代碼:
$("#searchclick").click(function(){
var address = document.getElementById('searchbar').value;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude2 = results[0].geometry.location.lat();
var longitude2 = results[0].geometry.location.lng();
var relocate = ("(" + latitude2 + ", " + longitude2 + ")");
alert("setting the center to: " + relocate);
map.setCenter(relocate);
} //when status is OK
}); // geocode
});
警報正確返回以下內容:setting the center to: (40.7143528, -74.0059731)
,但它不是使地圖正確的點的中心......
任何想法,爲什麼?