Created
February 1, 2010 05:32
-
-
Save whalesalad/291471 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // do the work | |
| $geo_url = "http://maps.google.com/maps/geo?q=%s&output=json&sensor=false&key=%s"; // query, api key | |
| $delay = 0; | |
| $uncoded_locations = $wpdb->get_results('select * from wp_arbesko_locations where `lat` = 0 AND `long` = 0'); | |
| foreach ($uncoded_locations as $key => $location) { | |
| $geocode_pending = true; | |
| while ($geocode_pending) { | |
| $address = $location->address.' '.$location->city.' '.$location->zipcode.' '.$location->country; | |
| $request_url = sprintf($geo_url, urlencode($address), $ARB_GMAPS_API_KEY); | |
| $json_response = file_get_contents($request_url); | |
| $response = json_decode($json_response); | |
| $status = $response->Status->code; | |
| if ($status == '200') { | |
| $coordinates = $response->Placemark[0]->Point->coordinates; | |
| $lat = $coordinates[1]; | |
| $long = $coordinates[0]; | |
| // UPDATE wp_arbesko_locations SET `lat` = 50.3943032, `long` = 7.5169719 WHERE location_id = 6 LIMIT 1 | |
| $query = sprintf("UPDATE wp_arbesko_locations SET `lat` = %s, `long` = %s WHERE location_id = %s LIMIT 1", $lat, $long, $location->location_id); | |
| Template::debug($query); | |
| $wpdb->query($query); | |
| $geocode_pending = false; | |
| } else if ($status == '620') { | |
| $delay += 100000; | |
| } else { | |
| $geocode_pending = false; | |
| echo "<p>"; | |
| echo "Address: ".$address." failed to geocode. ID: ".$location->location_id."."; | |
| echo "</p>"; | |
| } | |
| } | |
| usleep($delay); | |
| } | |
| // do the geocoding like a true thug | |
| include ARB_TEMPLATES.'admin_location_geocode.php'; | |
| return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment