English 中文(简体)
谷歌地图
原标题:Google Maps SetCenter function refusing to work

• 努力使我的SetaCenter发挥作用,但不是。

该守则是:

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

    });

B. 警示正确返回 缩略语 The Centre to: (40.7143528, -74.0059731)

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

任何想法为什么?

问题回答

Setcentretake a google.maps.LatLng Object. 修改你的法典如下:

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

见:

https://developers.google.com/maps/documentation/javascript/参比#Map>.setCenter

https://developers.google.com/maps/documentation/javascript/fer#LatLng>





相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签