Reputation: 413
I have problem with result of Geocoder.geocode({'placeId': placeId}) on specific location
(i.e. Main Street 34, Paris) then I will get address_components: street,sublocality,locality,country,postal_code.
function geocodePlaceId(geocoder, placeId, callback) {
geocoder.geocode({'placeId': placeId}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[0]) {
console.log(results[0]);
callback(results[0].address_components);
}
});
}
code above for the precise location (which contains street nmbr. street and city) returns address_components that are not important for me.
However I want administrative_area_level_2
and administrative_area_level_1
types. Unfortunately I googled a lot and nothing. I thought that this definition for my request can be helpfull
https://developers.google.com/maps/documentation/javascript/3.exp/reference#GeocoderComponentRestrictions but not.
Example: https://maps.googleapis.com/maps/api/geocode/json?&address=luka%20666%20brusno
I created request with exact address with street, number, city and returned address_components which contains only these keys: route, locality, country and postal_code, but if i change a request to .. address=brusno result contains administrative_area_level_2 and administrative_area_level_1. How can i got administrative_area_level_1 and administrative_area_level_2 for first option?
Do you have some idea how can I resolve this issue or can I influence returned types of address_components?
Upvotes: 0
Views: 860
Reputation: 7771
Based on the Google Maps Geocoding documentation, administrative_area_level_# indicates a civil entity below the country level. And not all nations exhibit these administrative levels. In most cases, administrative_area_level_# short names will closely match ISO 3166-2 subdivisions and other widely circulated lists; however this is not guaranteed as our geocoding results are based on a variety of signals and location data. So maybe that is the issue.
Also, regarding about the request using only the address=brusno, you will notice here that the administrative_area_level_# here is in the Banská Bystrica District not in the place that you use like Luka, Brusno.
If you query that address you will notice that it is the same result.
using address=Banská Bystrica District
https://maps.googleapis.com/maps/api/geocode/json?&address=Bansk%C3%A1%20Bystrica%20District
So maybe like the documentation state that not all place(Luka, Brusno)exhibit these administrative levels.
Upvotes: 0