0

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?

user1666761
  • 163
  • 2
  • 3
  • 13

1 Answers1

1

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

Community
  • 1
  • 1
Mauno Vähä
  • 9,688
  • 3
  • 33
  • 54
  • I put in the beginning of js function: setTimeout(function() {},300); , and usleep(300) into php cycle. Still doesn't work – user1666761 Oct 26 '12 at 14:28
  • I used it with around 1 sec (1000) before to loop over 200 addresses and it worked. – Mauno Vähä Oct 26 '12 at 14:30
  • it's kinda funny, because it's not working for me :-/. where exactly did you put timeout and what function/command did you use? – user1666761 Oct 26 '12 at 14:34
  • There is multiple examples already here and in google so its no use to repeat and write those codes again, i edited my answer with few good resources. – Mauno Vähä Oct 26 '12 at 14:43