Google's Geocoder returns wrong country, ignoring the region hint

后端 未结 13 1048
孤城傲影
孤城傲影 2020-12-07 21:03

I\'m using Google\'s Geocoder to find lat lng coordinates for a given address.

    var geocoder = new google.maps.Geocoder();
    geocoder.geocode(
    {
            


        
13条回答
  •  猫巷女王i
    2020-12-07 21:38

    I found problems with putting ",UK", setting the region to UK and setting bounds. However, doing ALL THREE seems to fix it for me. Here's a snippet:-

    var sw = new google.maps.LatLng(50.064192, -9.711914)
    var ne = new google.maps.LatLng(61.015725, 3.691406)
    var viewport = new google.maps.LatLngBounds(sw, ne);
    
    geocoder.geocode({ 'address': postcode + ', UK', 'region': 'UK', "bounds": viewport }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
    .....etc.....
    

提交回复
热议问题