google map api逆ジオコーディングとphpを使用して座標(lat、long)から最寄りの住所または都市を取得する関数が必要です...サンプルコードをいくつか教えてください
43178 次
1 に答える
34
GoogleMapsAPIのGClientGeocoderオブジェクトでgetLocationsメソッドを使用する必要があります
var point = new GLatLng (43,-75);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) {
// access the address from the placemarks object
alert (result.address);
});
編集:わかりました。あなたはこのようなものをサーバー側でやっています。これは、 HTTPジオコーディングサービスを使用する必要があることを意味します。これを行うには、リンクされた記事で説明されているURL形式を使用してHTTPリクエストを行う必要があります。HTTP応答を解析して、アドレスを引き出すことができます。
// set your API key here
$api_key = "";
// format this string with the appropriate latitude longitude
$url = 'http://maps.google.com/maps/geo?q=40.714224,-73.961452&output=json&sensor=true_or_false&key=' . $api_key;
// make the HTTP request
$data = @file_get_contents($url);
// parse the json response
$jsondata = json_decode($data,true);
// if we get a placemark array and the status was good, get the addres
if(is_array($jsondata )&& $jsondata ['Status']['code']==200)
{
$addr = $jsondata ['Placemark'][0]['address'];
}
注意:Googleマップの利用規約では、結果をGoogleマップに表示せずにデータをジオコーディングすることは禁止されています。
于 2010-01-13T05:35:59.967 に答える