Skip to content

Instantly share code, notes, and snippets.

@sillygwailo
Created March 30, 2012 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sillygwailo/2249822 to your computer and use it in GitHub Desktop.
Save sillygwailo/2249822 to your computer and use it in GitHub Desktop.
Convert iPhone and BlackBerry latitude and longitudes in Twitter profiles to city name
<?php
/*
* requires the GeoCoder PHP library https://github.com/sillygwailo/GeoCoder
*/
include_once("./GeoCoder/GeoCoder.php");
$f = fopen("File to read here", 'r+');
$o = fopen("File to write here", 'w+');
$g = new GeoCoder('geocoder.ca API key here');
while ($c = fgetcsv($f)) {
if ($c[0] != 'screen_name') {
$latlong = $c[2]; // in the CSV we're using, it's the third column
$latlong = str_replace('iPhone: ', '', $latlong);
$latlong = str_replace('ÜT: ', '', $latlong);
$latlong_array = explode(';', $latlong);
print_r($latlong_array);
$options['latt'] = $latlong_array[0];
$options['longt'] = $latlong_array[1];
$r = $g->ReverseGeoCoder($options);
$c[3] = $r->city; // replace the 4th column with the city name
fputcsv($o, $c);
}
}
fclose($f);
fclose($o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment