Darrin,
The Google Maps geocoding API is one of the shittiest services they offer.
The nested while loops are unnecessary btw, the one loop is iterating over
the list of elements, and the other is waiting on a semaphor to see if it
should keep retrying. The delay is due to that they rate limit you, since
they will only provide 15k addresses / day / IP address. When you remember
that there are 86,400 seconds per day, that means you can only realistically
make 1 request every 5.76 seconds, and not run into a cap or rate limit.
The easiest way to handle this sort of api is to chain load, where in you
make a request, wait for a response, process it, and then fetch the next
address from the queue. Their sample code has a bug in that it sends out as
many requests at once as possible, and then increases the delay each time a
request fails to load. This is particularly stupid since Google has proxy
servers that are capable of batching requests, and then asynchronously
respond with results as they are found.
Dave
On Tue, Jul 28, 2009 at 10:30 AM, Darrin Thompson <[email protected]>wrote:
> Last night I spent a couple of hours trying to find a clean way to
> implement this loop:
>
> http://code.google.com/apis/maps/articles/phpsqlgeocode.html#samplecode
>
> The main thing here is that each loop loop iteration is expensive, so
> whatever persistence mechanism is in place needs to happen right away,
> or at least frequently.
>
> The other thing is that Google gets to say slow down any time they
> want. They recommend that the writer add an artificial delay before
> each loop iteration, and to increase that delay by 0.1 second any time
> the 620 status shows up. (Also, if you get the slow down code, you
> need rerun that iteration.)
>
> Normally I just do a little combinator happiness and I'm done. Not so
> much here. Anyone care to weigh in on how you'd approach this?
>
> I tried putting together a loop utility where the delay was increased
> and iteration retried every time the iteration threw a particular
> exception. But I was like "try this" and factor was like "unbalanced
> branches" and then I was like "infer. doh! try this" and it was like
> "unbalanced branches over here now". I never did get it working. Plus,
> I was bothered by the nagging idea that there was probably an
> important utility somewhere I was missing.
>
> --
> Darrin
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
-=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk