Why can't Google Sheets find reverseGeocode method from Maps API? -
I am using a Google Sheet function which reverses a list lat / long coordinate. It looks like:
function getAdd (lat, lng) {if (lat == "") {return "You have to provide the coordinates of latitude for space"} if (LNG == "") {Return "You must provide longitudinal coordinates for the place"} var response = maps.newGeocoder (). ReverseGeocode (lat, lng); (Var i = 0; i & lt; response.results.length; i ++) {var results = response Results [i]; Utilities.sleep (1000); Return result. Formatted; }}; <1> <1> Q1: Why is Google Sheet giving me the following error: "Can not find the method reverse ject (object, (class))"?
> Question 2: Once I fix this, how can I get the name of the country from the results array instead of the full address?
You are trying to return a result for each result in the response result. Instead, you have to choose one:
function getAdd (lat, lng) {if (lat == "") {return "You have to provide the coordinates of latitude for space"} (Lng == "") {Return "You have to provide longitudinal coordinates for the place"} var reaction = map.newscoder (). Reverse geocode (latitude, lng); Return response. Results [0]. Formatted_address; };
If you are just searching for the country, then the format of the result object is here:
In that case, repeating the result through [0] To see the object and test that type "country" is included, if it does, select the results [0] .address_components [i] .short_name where I am your iterator or use long_name instead
Comments
Post a Comment