So I am using geocode service from Google Map APIv3. I have restricted search around 'Switzerland/CH'.
But when I typed invalid characters like !x! or xz etc, I didn't get 'Invalid Address' rather I got 'Switzerland' as a result in address_components
array but it returns 'Invalid Address' if country restriction was not applied.
But I want country restriction and also return an error result, If user types something invalid.See My Code is below.
My Code:
function placeSearchBox() {
var searchBoxText = document.getElementById('locationSearch').value;
console.log('placeboxText',searchBoxText);
if (searchBoxText.length > 0) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
address: searchBoxText,
componentRestrictions: {
country: 'CH'
}
}, function (data, status) {
console.log(data);
if (status === google.maps.GeocoderStatus.OK && data.length > 0) {
searchResultOfGmapObj = data[0];
dispalySearchResult(data[0]);
console.log('GeoCodedAddress',data[0]);
vm.site.SiteAddress = searchBoxText;
} else alert("Invalid address");
});
}
}
So why is it not returning invalid address or Wrong Status?