Skip to content

Instantly share code, notes, and snippets.

@zofe
Created February 8, 2016 10:41
Show Gist options
  • Select an option

  • Save zofe/f40cdd43074b89ca0fa1 to your computer and use it in GitHub Desktop.

Select an option

Save zofe/f40cdd43074b89ca0fa1 to your computer and use it in GitHub Desktop.
<?php
....
public function getLatlon()
{
$province = Provincia::all();
foreach($province as $p)
{
/** @var \App\Provincia $p */
$region = $p->NOME.', italy';
$region = str_replace(" ", "+", $region);
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?sensor=false&address=$region");
$json = json_decode($json);
$status = $json->status;
if($status=="OK")
{
$lat = $json->results[0]->geometry->location->lat;
$lon = $json->results[0]->geometry->location->lng;
$p->LAT = $lat;
$p->LON = $lon;
$p->save();
echo $p->NOME."<br>";
flush();
}
sleep(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment