Created
December 16, 2016 00:25
-
-
Save ko31/3d80cce2b5c4cd7cf114e942c4c84ede to your computer and use it in GitHub Desktop.
【PHP】出身地から緯度・経度を取得したデータを作る
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 | |
$key = 'xxxxxxxxxx'; | |
$data = file_get_contents("kishi_all.json"); | |
$data = json_decode($data); | |
$maps = array(); | |
foreach($data as $kishi) { | |
$result = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($kishi->birthplace).'&key='.$key); | |
$result = json_decode($result, true); | |
if ($result['status'] != 'OK') { | |
continue; | |
} | |
$maps[] = array( | |
'no' => $kishi->no, | |
'name' => $kishi->name, | |
'birthplace' => $kishi->birthplace, | |
'image' => $kishi->image, | |
'lat' => $result['results'][0]['geometry']['location']['lat'], | |
'lng' => $result['results'][0]['geometry']['location']['lng'], | |
); | |
echo $kishi->no." ".$kishi->name."\n"; | |
sleep(1); | |
} | |
$json = json_encode($maps); | |
file_put_contents('map.json', $json); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment