I'm getting incorrect country codes when using Google Places API to geocode point locations. This happens mainly near country borders so I suppose that Places API is using a different source for country borders (with less precision) than the one shown in the Google Map tiles.
In the example below, the point is clearly inside France but the returned ISO code by Google Places is "ES" for "Spain".
function initMap() {
var geocoder = new google.maps.Geocoder;
var point = new google.maps.LatLng(42.4241355,2.2915667);
var map = new google.maps.Map(document.getElementById('map'), { zoom: 16, center: point });
var country_name = "Undefined";
geocoder.geocode({'location': point}, function(results, status, country_name) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {
for (var i=0; i < results[0].address_components.length; i++) {
for (var j=0; j < results[0].address_components[i].types.length; j++) {
if (results[0].address_components[i].types[j] == "country") {
country = results[0].address_components[i];
}
}
}
country_name = country.short_name;
} else {
country_name = "Geocoder no results found";
}
} else {
country_name = 'Geocoder failed due to: ' + status;
}
var marker = new google.maps.Marker({ position: point, map: map });
var infowindow = new google.maps.InfoWindow({ content: country_name });
infowindow.open(map, marker);
});
}
#map { height: 400px; width: 100%; }
<div id="map"></div>
<script async defer src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyABsURr0TnnANUUgsqN_Rk2VXhqgZfZrEk&callback=initMap"> </script>