1

SetCenter Function を機能させようとしていますが、そうではありません。

コードは次のとおりです。

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

しかし、マップの中心が正しいポイントになっていません...

理由はありますか?

4

1 に答える 1

5

セットセンターはgoogle.maps.LatLngオブジェクトを取ります。コードを次のように変更します。

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

見る:

setCenter

LatLng

于 2012-05-03T01:41:25.593 に答える