So for my work i implemented a simple address search that uses Googles AutoComplete API. This has worked fine for sometime now but recently we ran into an issue with incorrect addresses coming into the system. I worked out the issue occurs when you search for an address with a unit number.
To replicate the issue. Enter any address here that has a unit number. https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete
Eg. 10/311 Flemington Street
Select any result that comes up. The marker on the map will now instead show '10 Flemington Street'. So the unit number becomes the street number.
Here's a modified snippet of my code showing where the street number is lost and the unit number becomes the street number.
var input = document.getElementById('address_autocomplete')
var options = {
types: ['address'],
componentRestrictions: {country: 'au'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
autocomplete.addListener('place_changed', addressCallBack);
function addressCallBack() {
var place = autocomplete.getPlace();
console.log(place.address_components); //unit number is now the street number
}
I haven't been able to find any info on this so if i am missing something i'd love to know or at least make this issue known.
For now i have a work around hack to keep things running.
EDIT - Here is a test i did demonstrating the issue
I searched a randomly selected address. I then selected the first result "23/45 Wantirna Road, Ringwood VIC, Australia", which means Unit 23, 45 Wantirna road (in Australia at least)
After selecting the search result, a request is then sent to googles place service to get further details on the location. https://maps.googleapis.com/maps/api/place/js/PlaceService.GetPlaceDetails
Response
/**/_xdc_._knjkfp && _xdc_._knjkfp( {
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "23",
"short_name" : "23",
"types" : [ "street_number" ]
},
{
"long_name" : "Wantirna Road",
"short_name" : "Wantirna Rd",
"types" : [ "route" ]
},
{
"long_name" : "Ringwood",
"short_name" : "Ringwood",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Maroondah City",
"short_name" : "Maroondah",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Victoria",
"short_name" : "VIC",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Australia",
"short_name" : "AU",
"types" : [ "country", "political" ]
},
{
"long_name" : "3134",
"short_name" : "3134",
"types" : [ "postal_code" ]
}
],
"geometry" : {
"location" : {
"lat" : -37.8187267,
"lng" : 145.2275479
},
"viewport" : {
"northeast" : {
"lat" : -37.8173781197085,
"lng" : 145.2287786302915
},
"southwest" : {
"lat" : -37.82007608029149,
"lng" : 145.2260806697085
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"name" : "23 Wantirna Rd"
},
"status" : "OK"
}
)
As you can see the response shows that the address is now "23 Wantirna Road, Ringwood VIC, Australia". This means that the Place service is mistaking the unit number as the street number. The street number in this case just needs to be 45 not 23.