'Google place details street numbers with letters
When I do search in google's autocomplete I see correct address. Example:
Pavlichenko Street, 20b, Bila Tserkva, Kyiv Oblast, Ukraine
This address has place_id:
EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk
I need to get a street number which is "20b". To do so I use Place Details API: https://maps.googleapis.com/maps/api/place/details/json?placeid=EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk&key=MY_KEY
And here what is in response:
"address_components" : [
{
"long_name" : "20",
"short_name" : "20",
"types" : [ "street_number" ]
},
{
"long_name" : "Pavlichenko Street",
"short_name" : "Pavlichenko Street",
"types" : [ "route" ]
},
{
"long_name" : "Bila Tserkva",
"short_name" : "Bila Tserkva",
"types" : [ "locality", "political" ]
...
But "20" is actually different house, I need "20b". Same happens to all streets with letters. Is there way to solve this problem? Thank you
Solution 1:[1]
The long place ID EjtQYXZsaWNoZW5rbyBTdHJlZXQsIDIwYiwgQmlsYSBUc2Vya3ZhLCBLeWl2IE9ibGFzdCwgVWtyYWluZSIwEi4KFAoSCVcssl0EQtNAEeDmEfl02RgXEBQqFAoSCVGxb54DQtNAEbhYfU4LYvbk
indicates that this address is not present in Google database. They try to interpolate it to the best known position that matches your search.
Note that the existing in database addresses have a short place IDs, something like ChIJNSfioSOjpBIRSwaYW7O3LJY
.
Your prediction has a following type
"types":[
"route","geocode"
]
So it looks like Google could resolve it to route level, but not to street address level.
I can suggest reporting a missing address to Google data team as explained in the documentation
https://support.google.com/maps/answer/3094088
I hope this addresses your doubt.
Solution 2:[2]
In case it helps someone, we use a regex to check whether a street number is of a "special" format, e.g. 3a, or even 3/24, both of which are reduced to just "3" by Google.
We use the "formatted" address as a reference check. Feel free to modify to match your needs:
parseStreetNumber(streetNumber, formatted) {
//Handle a format like 23/241 or 3a, which Google strips
const regex = new RegExp(`^([0-9a-z]+/${streetNumber}|${streetNumber}[a-z])`, 'i')
const matches = formatted.match(regex)
if (matches) {
return matches[1]
}
//Return as is
return streetNumber
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | xomena |
Solution 2 | Adam Reis |