Created
April 22, 2013 21:48
-
-
Save JoaoVagner/5438842 to your computer and use it in GitHub Desktop.
TASK Fuelphp que procura endereços sem geo localização, requisita o google maps, e salva os daods
This file contains 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 | |
namespace Fuel\Tasks; | |
class Geo { | |
public static function run() { | |
$mongo = \Fuel\Core\Mongo_Db::instance(); | |
$process = $mongo->get_where('companies', array('address.geo' => array('$exists' => false))); | |
echo "STARTING Process \n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
foreach($process as $k => $company) { | |
echo "Looping Companies \n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
echo "Requesting Google MAPS! \n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
$addressCompany = $company['address']['address'] . ',' . $company['address']['number'] . ',' . $company['address']['district'] . ', ' . $company['address']['city'] . ', ' . $company['address']['state']; | |
$urlGmaps = "http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($addressCompany)."&sensor=false"; | |
$json = \Fuel\Core\Request::forge($urlGmaps, 'curl')->execute()->response(); | |
$myJson = json_decode($json->body); | |
$location = $myJson->results[0]->geometry->location; | |
echo "Get MAPS Complete! \n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
$mongo->where(array('_id' => $company['_id']))->update('companies', array( | |
'address.geo' => $location, | |
'address.formatted_address' => $myJson->results[0]->formatted_address)); | |
echo "Company ". $company['trading_name']. " Process Lat and Lng \n"; | |
echo "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"; | |
} | |
echo "Complete process! \o/ \n\r"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment