Unknown property result_type using the Reverse Geocoding JavaScript API
Asked Answered
D

0

6

I was trying to use the Google Maps Reverse Geocoding (translating a location on the map into a human-readable address) via the JavaScript API, and I wanted to filter the results to get only the street addresses.

As I saw in the docs, there is a result_type optional parameter for this request, but when specifying it, I get the following error:

InvalidValueError: unknown property result_type

I include the API by loading this script: https://maps.googleapis.com/maps/api/js?key=MY_API_KEY

And here is the code I use for reverse geocoding:

geocoder = new google.maps.Geocoder();
geocoder.geocode(
    {
        location: {lat: parseFloat(lat), lng: parseFloat(lng)},
        result_type: 'street_address'
    },
    function(results, status) {
        if (status === 'OK') {
            console.log(results);
        }
    }
);

A small playground fiddle: https://jsfiddle.net/scebotari66/30nshzb6/.

However, when I try this via a direct HTTP request (https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&result_type=street_address&key=MY_API_KEY), everything works as expected.

Dashtikavir answered 2/6, 2017 at 7:57 Comment(7)
Doc says 'This parameter is available only for requests that include an API key or a client ID.'Alric
I saw that. I use an API key when including the Javascript API. I've update my question to reflect this. Thanks!Dashtikavir
try result_type: ['street_address']Alric
Tried it! The same error..Dashtikavir
last try "types" : [ "street_address" ] should work based on the geocode api responseAlric
Tried this and also tried to specify it as a string, the same kind of error: InvalidValueError: unknown property typesDashtikavir
Let us continue this discussion in chat.Alric

© 2022 - 2024 — McMap. All rights reserved.