Sam Stern
Sam Stern

Reputation: 25134

Google Maps Reverse Geocoding only returning "APPROXIMATE" location

I am using the reverse geocoding API (client side) to turn lat, long coordinates into street addresses. These lat longs are taken directly from a draggable marker on the map, so they have many decimal places of information.

If I put it in San Francisco, for example, I drag the marker and send the { lat, lng } pair to the API. I get back something very general like "San Francisco, CA" or at best "South of Market, San Francisco, CA, USA".

I know google has street information in this area because I can use the forward geocoding API perfectly.

Is there any parameter I might be missing that would cause this? Here is my code:

maps.reverseGeocode = function(pos, callback) {
    maps.geocoder.geocode({
        latLng: pos,
        bounds: maps.map.getBounds()
    }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            console.log("Reverse Geocode:", results);
            callback(results[0]);
        } else {
            console.log('Could not geocode: ' + status);
            callback(undefined);
        }
    });
};

Where pos is taken directly from the map marker object.

Upvotes: 0

Views: 907

Answers (1)

Sam Stern
Sam Stern

Reputation: 25134

Figured this out pretty quickly. It was because I was including the bounds parameter in the request. Removing bounds gives me highly accurate results. I am now only using bounds in forward geocoding.

Upvotes: 1

Related Questions