Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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