-
-
Save gotomypc/3356643 to your computer and use it in GitHub Desktop.
Convert iPhone and BlackBerry latitude and longitudes in Twitter profiles to city name
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 | |
/* | |
* 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