试图让我的 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)
但它没有使地图的中心成为正确的点......
任何想法为什么?