简体   繁体   中英

Google maps geocoder returns Not found

I'm trying to use the geocoder to get co-ordinates for the following address:

1945 Barton Street, Hamilton, ON, L8H2Y7

Searching the address on google maps itself finds the address: http://g.co/maps/5axb5 . Using the geocode url also returns fine. http://maps.googleapis.com/maps/api/geocode/json?address=1945+BARTON+STREET,+HAMILTON,+ON,+L8H2Y7&sensor=false

However, when I use the api (my code below), it returns not found.

图片

Code: (this works fine for several other addresses I'm searching)

if (geocoder) {
    geocoder.geocode( {'address': fullAddress }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
        } else {
            alert("Geocoding failed: " + status + "  " + fullAddress);
        }
    });
}

The "actual" address is "1945 Barton Street East , Hamilton, ON L8H2Y7, Canada", but maps and the direct url still find the place fine, only the geocoder doesn't.

Any ideas as to why this might be happening?

EDIT: I figured it out. It was a different address that it legitimately couldn't find (not on google maps or using the geocoder), but because the request was being done asynchronously by the time the geocoder realized it couldn't find the address, the loop had already changed the address value to another address which it could find. Seems like I've got some work ahead of me..

it's strange because it work's on my live demo check this

Live Demo

Do you have more code somewhere??

Update

I test the service with the plus symbol, and even without canada and still worked

here's examples

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM