Search code examples
phpjavascriptlocationcoordinatesgoogle-geocoder

why Geocoder google doesn't want to recognize more addresses?


I have one array with coordinates (lat, long)... This array has about 60-80 items...

In my foreach cycle there are...

...{
$lat = substr($xx[1],0,8);
$long = substr($xx[0],0,8);

?>

<script type="text/javascript">
// <![CDATA[
$(function() {

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

function geocodePosition(pos,pos2) {
  geocoder.geocode({
    latLng: new google.maps.LatLng(pos,pos2)
  }, function(responses) {
if (responses && responses.length > 0) {
   console.log(responses[0].formatted_address);
} else {
   console.log('Cannot determine address at this location.');
    }
  });
}
geocodePosition(<?php echo $lat ?>,<?php echo $long ?>);

}); 

// ]]>
</script>

<?php } ...

Geocoder geocodes at the most 5 coordinates, others come with output 'Cannot determine address at this location.'

When I take some of those, which "could not be determined", I use them manually (just 1 item = lat and long, not the whole array) it works.

So where's the problem?


Solution

  • You cant request addresses too fast in a row (blocked by google), you need to use small setTimeout() between when doing it inside loop. Also note that you can request only 2500 addresses per day with basic api, with business over 100000 source from google.

    How to avoid google map geocode limit

    Setting timeout to simulate pause

    Geocode markers from PHP array

    Avoid geocode limit - js / html source