2011-07-17 12 views
2

私のデータベースにユーザーとそのアドレスのリストがあります。 私は町からcooridnatesを取得するためにcronジョブを実行したいです。 Google Maps APIにリクエストを送信し、座標を使用して回答を得る方法はありますか?Googleマップ経由で町から座標を取得するPHPのapi

ラウラ

答えて

2

curlは...いくつかのスクリプトからの抜粋。.. cURLのためのヘルパー関数です

$address = str_replace(" ", "+", $_GET["address"]); 
$data = curl("https://maps.googleapis.com/maps/api/geocode/json?address=$address&sensor=false"); 
$data = json_decode($data, true); 
$json["city"] = $data["results"][0]["address_components"][2]["long_name"]; 
$json["country"] = $data["results"][0]["address_components"][3]["long_name"]; 
$json["iso"] = strtolower($data["results"][0]["address_components"][3]["short_name"]); 
$json["ll"] = $data["results"][0]["geometry"]["location"]["lat"].",".$data["results"][0]["geometry"]["location"]["lng"]; 
echo json_encode($json); 
関連する問題