Google maps 谷歌地图设置中心功能拒绝工作
正在尝试让我的设置中心功能正常工作,但它无法正常工作 代码如下:Google maps 谷歌地图设置中心功能拒绝工作,google-maps,google-maps-api-3,maps,Google Maps,Google Maps Api 3,Maps,正在尝试让我的设置中心功能正常工作,但它无法正常工作 代码如下: $("#searchclick").click(function(){ var address = document.getElementById('searchbar').value; var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': address}, function(results, status)
$("#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
});
警报将正确返回以下内容:将中心设置为:(40.7143528,-74.0059731)
但它并没有使地图的中心成为正确的点
你知道为什么吗?设置中心需要一个
google.maps.LatLng
对象。将代码更改为:
var relocate = new google.maps.LatLng(latitude2, longitude2);
alert("setting the center to: " + relocate);
map.setCenter(relocate);
见:
设置中心接受一个
google.maps.LatLng
对象。将代码更改为:
var relocate = new google.maps.LatLng(latitude2, longitude2);
alert("setting the center to: " + relocate);
map.setCenter(relocate);
见: