Skip to content

Instantly share code, notes, and snippets.

@weivall
Created April 3, 2014 22:28
Show Gist options
  • Save weivall/9964154 to your computer and use it in GitHub Desktop.
Save weivall/9964154 to your computer and use it in GitHub Desktop.
geocode
$ssss = $wpdb->get_results("select name, id from wp_cities");
foreach($ssss as $s){
$z = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address={$s->name}&sensor=false");
$a = json_decode($z, true);
$lat = $a['results'][0]['geometry']['location']['lat'];
$lng = $a['results'][0]['geometry']['location']['lng'];
$wpdb->update(
'wp_cities',
array( 'lat' => $lat, 'lng' => $lng ),
array( 'id' => $s->id),
array( '%f', '%f' )
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment