Google地图SetCenter功能拒绝工作 [英] Google Maps SetCenter function refusing to work

查看:125
本文介绍了Google地图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(中心到:+ relocate);

map.setCenter(relocate);

} //状态为OK时

}); / / geocode

});

警报正确返回以下内容:将中心设置为:(40.7143528, -74.0059731)



但它没有使地图的中心点成为正确的点...



任何想法为什么?

解决方案

设置中心需要一个 google.maps.LatLng 对象。将您的代码更改为:

  var relocate = new google.maps.LatLng(latitude2,longitude2); 
alert(将中心设置为:+ relocate);
map.setCenter(relocate);

见:

定位中心



LatLng


Trying to get my SetCenter Function to work but its not.

Here is the code:

$("#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

    });

the alert correctly returns the following: setting the center to: (40.7143528, -74.0059731)

but its not making the center of the map the correct point...

Any ideas why?

解决方案

Set center takes a google.maps.LatLng object. Change your code to:

var relocate = new google.maps.LatLng(latitude2, longitude2);
alert("setting the center to: " + relocate);
map.setCenter(relocate);

See:

setCenter

LatLng

这篇关于Google地图SetCenter功能拒绝工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆