Search code examples
javascriptgoogle-mapsgoogle-maps-api-3google-geocoder

Difference results between Geocoding services and search on gMap


I want to get the latitude and longitude for this adress : Boulevard de la Marne Zone industrielle, COULOMMIERS, 77120, France

I'm adding the api to my page with :

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>

When I use gmaps the result is good but when I want to retrieve it by the API :

 geocoder = new google.maps.Geocoder();
 geocoder.geocode({ 'address': myAdress, 'region': 'FR'}, function (results, status) {...});

It does the following request :

https://maps.googleapis.com/maps/api/js/GeocodeService.Search?4sBoulevard%20de%20la%20Marne%20%20Zone%20industrielle%20%20COULOMMIERS%2077120%20&7sUS&9sfr-FR&callback=_xdc_._lsoj9s&token=53058

and the result is near Bamako...

If I use the viewport bounds it does the following request :

https://maps.googleapis.com/maps/api/js/GeocodeService.Search?4sBoulevard%20de%20la%20Marne%20%20Zone%20industrielle%20%20COULOMMIERS%2077120%20&6m6&1m2&1d40.513799&2d-5.844727000000034&2m2&1d51.727028&2d10.854491999999936&7sUS&9sfr-FR&callback=_xdc_._c84svr&token=29019

It's better (it's in France) but it's not that

The query works well on the website google map : https://maps.google.fr/maps?q=Boulevard+de+la+Marne++Zone+industrielle,++COULOMMIERS,+77120&hl=fr&ll=48.487486,3.922119&spn=1.541855,4.22699&sll=50.485474,25.620117&sspn=23.748757,67.631836&hq=Boulevard+de+la+Marne++Zone+industrielle,++COULOMMIERS,+77120&radius=15000&t=m&z=9

It seems that the only way to get it is by doing the following request : http://maps.googleapis.com/maps/api/geocode/json?address=Boulevard%20de%20la%20Marne%20Zone%20industrielle,%20COULOMMIERS,%2077120&components=country:FR&sensor=false

I don't understand why the result are different when I use the viewport and not the country (the two results are in the bounds of the viewport)


Solution

  • Boulevard de la Marne Zone industrielle, COULOMMIERS, 77120, France is not an address, it is a "place".

    The geocoder finds the location of Via De La Marne from that input:

    http://www.geocodezip.com/v3_example_geo2.asp?addr1=Boulevard de la Marne Zone industrielle, COULOMMIERS, 77120, France&geocode=1

    Found 1 results for Boulevard de la Marne Zone industrielle, COULOMMIERS, 77120, France
    [ 0 ]: Av De La Marne, Bamako, Mali (12.6417952, -7.988396299999977)
    

    The first result from the Places API looks more correct:

    http://www.geocodezip.com/v3_example_geo2.asp?addr1=Boulevard de la Marne Zone industrielle, COULOMMIERS, 77120, France&place=1

    Found 20 results for Boulevard de la Marne Zone industrielle, COULOMMIERS, 77120, France
    [ 0 ]: Zone Industrielle, Boulevard de la Marne, Coulommiers, France (48.804329, 3.0923729999999523)
    [ 1 ]: Boulevard de la Marne, Coulommiers, France (48.803048, 3.092110000000048)
    [ 2 ]: 21 Boulevard de la Marne, Coulommiers, France (48.806634, 3.0937430000000177)
    ...