Geocoder.geocode({'placeId': placeId}) doesn't return administrative_area_level_2/1 - google-maps

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?

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.

Related

Uniquie Identifier check for ArcGIS REST Geocoded Data

I am querying the ArcGIS Online REST API to Geocode and normalise a address string the user enters into discrete data. An example of the normalised returned data:
VALID (RFC 8259)
Formatted JSON Data
{
"spatialReference":{
"wkid":102100,
"latestWkid":3857
},
"candidates":[
{
"address":"12 Queen Street, Melbourne Central, Melbourne, 1010",
"location":{
"x":19454998.013352692,
"y":-4417395.0764459781
},
"score":100,
"attributes":{
"Match_addr":"12 Queen Street, Melbourne Central, Melbourne, 1010",
"Addr_type":"PointAddress",
"StNumber: 12",
"StName: Queen",
"StType: Street",
"StAddr":"12 Queen Street",
"City":"Melbourne",
"Country: AUS"
},
"extent":{
"xmin":19454886.693861898,
"ymin":-4417534.1797140706,
"xmax":19455109.33284349,
"ymax":-4417255.9749970241
}
}
]
}
This GIS data is to be stored locally in a database with fields:
coords :POINT(X,Y)
match_addr: varchar
addr_type: varchar
st_addr: varchar
city: varchar
In future if the ArcGIS Geocoding API is again called and returns the same address I need a way to check my local database to make sure the same address does not already exist locally.
No UID is returned in the results and I can not use anything that relies on the coordinates as an apartment building may share the same coordinates, but be a different address.
Could I use the match address string to check for an existing entry in the local table, or is there a better way?

Getting city from geocode results Google Maps Api

I am using the Google Maps API (https://maps.googleapis.com/maps/api/geocode/xml) to geocode places and addresses. However, the results seem inconsistent. The administrative_area_level_2 and locality OR the locality and sublocality_level_1 seem to overlap. But, depending on the address, the overlap is different. One of the things I need to do is determine the city. The documentation states that the locality is the equivalent of a city depending on the country.
If I geocode "Noord-Holland, Nederland" which is a province I get:
country:Nederland
administrative_area_level_1: Noord-Holland
I can understand. All seems well...
If I geocode "Amsterdam, Noord-Holland, Nederland" I get the following result:
country:Nederland
administrative_area_level_1: Noord-Holland
administrative_area_level_2:Amsterdam
locality:Amsterdam
Here I start not understanding the result. Why is Amsterdam listed as an administrative_area_level_2 as well as a locality? Maybe there is a higher governamental body with the same name? But ok, Amsterdam is the locality, thus the city. Which is correct.
If I geocode "Anton de Komplein 150, 1102 CW Amsterdam, Noord-Holland, Nederland" I get the following results:
country:Nederland
administrative_area_level_1:Noord-Holland
administrative_area_level_2:Amsterdam
locality:Amsterdam-Zuidoost
sublocality_level_1:Amsterdam-Zuidoost
Now I really don't understand.
Here is Amsterdam-Zuidoost mentioned twice
Why is the locality here "Amsterdam-Zuidoost"? It is not the city... I would have assumed that "Amsterdam" would be the locality and "Amsterdam-Zuidoost" the sublocality_level_1.
Can someone explain how i should interpretate the results?
I've had a look at your examples and I believe these are data issues that should be reported to Google.
Let's explain my findings:
The request for 'Amsterdam, Noord-Holland, Nederland'
https://maps.googleapis.com/maps/api/geocode/json?address=Amsterdam%2C%20Noord-Holland%2C%20Nederland&key=MY_API_KEY
returns the following address components for me
"address_components":[
{
"long_name":"Amsterdam",
"short_name":"Amsterdam",
"types":[
"locality","political"
]
},
{
"long_name":"Government of Amsterdam",
"short_name":"Government of Amsterdam",
"types":[
"administrative_area_level_2","political"
]
},
{
"long_name":"North Holland",
"short_name":"NH",
"types":[
"administrative_area_level_1","political"
]
},
{
"long_name":"Netherlands",
"short_name":"NL",
"types":[
"country","political"
]
}
]
Note that administrative_area_level_2 has a name 'Government of Amsterdam'. I understand you might be using the Dutch language to get results
https://maps.googleapis.com/maps/api/geocode/json?address=Amsterdam%2C%20Noord-Holland%2C%20Nederland&language=nl&key=MY_API_KEY
In this case I have:
{
"long_name":"Amsterdam",
"short_name":"Amsterdam",
"types":[
"locality","political"
]
},
{
"long_name":"Amsterdam",
"short_name":"Amsterdam",
"types":[
"administrative_area_level_2","political"
]
}
So at this point it looks like the Dutch version is not translated correctly, we have 'Government of Amsterdam' in English and 'Amsterdam' in Dutch. This is a data issue. By the way you can see the administrative area level 2 here:
https://www.google.com/maps/place/Government+of+Amsterdam,+Amsterdam,+Netherlands/#52.3544136,4.7585038,11z/data=!3m1!4b1!4m5!3m4!1s0x47c63fb5949a7755:0xe4f20c148755745!8m2!3d52.3666969!4d4.8945398
The second example is a bit more complicated.
https://maps.googleapis.com/maps/api/geocode/json?address=Anton%20de%20Komplein%20150%2C%201102%20CW%20Amsterdam%2C%20Noord-Holland%2C%20Nederland&key=MY_API_KEY
First of all you should be aware that for street address level searches you will get address components and formatted address in local language as described in the localization of street addresses article. So doesn't matter what language we specify English or Dutch we will see the Amsterdam as the administrative area level 2 and this is exactly the same data issue that we faced in the first example, it should be translated to 'Regering van Amsterdam' on Google side.
Referring to the locality component. It's really weird that Amsterdam-Zuidoost is defined as locality in Google database. I can see it as shown in the screenshot and it looks like a sublocality:
https://www.google.com/maps/place/Amsterdam-Zuidoost,+Netherlands/#52.2569773,4.995519,12z/data=!4m5!3m4!1s0x47c60c069aab8879:0x249b64218cad1744!8m2!3d52.3079989!4d4.9715451
However if you check this feature in the Geocoder tool, it clearly states that this is a locality feature:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#place_id%3DChIJeYirmgYMxkcRRBetjCFkmyQ
Note the pace ID is ChIJeYirmgYMxkcRRBetjCFkmyQ. I believe this also might be a data issue on Google side.
I would suggest sending a feedback to Google data team following the Google Maps help center:
https://support.google.com/maps/answer/3094045?hl=en&ref_topic=3093612
I hope my answer clarifies your doubts!

Region/counties google place codes?

Any one know in which ISO format google places returns the place object short_name for regions ?
I have this code:
var place = places.getPlace();
var type = place.address_components[0].types[0];
switch(type) {
case 'country': document.getElementById('country').value=place.address_components[0].short_name;
break;
case 'locality':
document.getElementById('town').value=place.address_components[0].long_name;
break;
default: //when is not a country or a city
document.getElementById('regioncode').value=place.address_components[0].short_name
;
In case is a region/county it gets the shor_name of it, but is some cases it returns a code like searching for "Balearic Islands, Spain" it return "PM" (which stands for ISO 3166-2:ES), but if I search "Kalmar län, Sweden" I get exactly the same for short_name as long_name which is "Kalmar County" instead of "H" (which stands for ISO 3166-2:SE)so my question is: Why Google sometimes return ISO 3166-2 values for regions/counties and sometimes the long_name value, is it any logic behind this? Can I force to ONLY return ISO values for short_names ??? thank you
According to Google Documentation:
short_name is an abbreviated textual name for the address component,
if available. For example, an address component for the state of
Alaska may have a long_name of "Alaska" and a short_name of "AK" using
the 2-letter postal abbreviation.
The Key word here is "if available". Kalmar County must not have a short name

google.maps.Geocoder.geocode not always returns Australian postcode

I'm using the google.maps.Geocoder class to resolve Australian addresses entered into a free form input field:
pass the entered address (such as "Parramatta") in the google.maps.GeocoderRequest.address field,
call google.maps.Geocoder.geocode
and then show all returned google.maps.GeocoderResult.formatted_address fields to the user so they can select one.
Problem is that the returned formatted_address fields not always contains the postcode.
Pass "Parramatta" into google.maps.GeocoderRequest.address ->
receive formatted_address "Parramatta NSW, Australia"
Pass "Strathfield" into google.maps.GeocoderRequest.address ->
receive formatted_address "Strathfield NSW 2135, Australia"
Looks to me like this is a fault in Google's database, but I'm not sure.
Is there a way to resolve addresses that always gives you the postcode?
If you reverse geocode the location returned for Parramatta, it does contain a post code:
{
"long_name": "2150",
"short_name": "2150",
"types": [
"postal_code"
]
}
That is correct according to Wikipedia

How do I get the parent city for a suburb using Google Maps API?

I'm using Google Places Auto complete API. If I search for a particular suburb, let's say Richmond in Victoria, Australia I get the following address components returned:
0:Object
long_name: "Richmond"
short_name: "Richmond"
types: Array[2]
0: "locality"
1: "political"
1: Object
long_name: "Victoria"
short_name: "VIC"
types: Array[2]
0: "administrative_area_level_1"
1: "political"
2: Object
long_name: "Australia"
short_name: "AU"
types: Array[2]
0: "country"
1: "political"
This is great, however Richmond is a suburb of Melbourne and for the purpose of my app I need to know this. How can I get the API to return the parent city if the locality is within one? If you look at the following URL you can see that it places Richmond in Melbourne, Victoria, Australia so I'm assuming it's possible somehow to get this information via the API?
https://maps.google.com/maps/place?q=Richmond&ftid=0x6ad64259018db945:0x5045675218ce810
Alas the City and/or Region info is not included in the Geocoding API return.
As a rough solution for location based searches I do km radius for city and region:
Worldwide No filter
Country Available from geocode
State Available from geocode
Region 50 KM Radius from latlong
City 20 KM Radius from latlong
Postcode Available from geocode
Suburb Available from geocode (Locality)
Radius User defined radius from latlong
I did try using the 'bounds' values but without real success (https://developers.google.com/maps/documentation/geocoding/).
If you need to be more accurate than that then you're making quite a large reference database.
Use the returned Latlng to reverse geocode: https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding