Search code examples
geolocationgeocodinggoogle-geocoder

I get false lat long for the cities of Dom-Tom when i use geocoder google


my script

<script type="text/javascript">
// ....
//....

var adresse = jQuery.trim(region) + ", " +jQuery.trim(adresse) + ", " + jQuery.trim(codePostal) + ", " + jQuery.trim(ville) + ", " +  jQuery.trim(pays);

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

                    geocoder.geocode({ address: adresse, region: 'no' },
                    function (coords, status) {
                         if (status.toLowerCase() == 'ok') {
                                var lat = coords[0].geometry.location.lat();
                                var lon = coords[0].geometry.location.lng();    
                                console.log("lat :"+lat+",  lon :"+lon);

                         }
                         else {
                            alert("address not found");
                         }
                    } );

</scrip>

I have a problem latlong the region dom-tom of France, I have latlong false when I insert this address "La Réunion, 9 Rue des Poivriers, 97400, Saint-Denis, France" I like latlong => (lat: 48.936181, lon: 2.3574429999999893) but it's false

I hope someone has a solution, if so thank you for helping me (Sorry about my english!)


Solution

  • I found the solution finally just eliminate the country for overseas regions like that :

    <script type="text/javascript">
    // ....
    //....
    
    if(jQuery.trim(pays) == 'France'){
    var adresse = jQuery.trim(region) + ", " +jQuery.trim(adresse) + ", " + jQuery.trim(codePostal) + ", " + jQuery.trim(ville);
    }
    else{
    var adresse = jQuery.trim(region) + ", " +jQuery.trim(adresse) + ", " + jQuery.trim(codePostal) + ", " + jQuery.trim(ville) + ", " +  jQuery.trim(pays);
    }
    
    //...
    
    </script>
    

    Thanks you a lot AlexWien