- GoogleMap
-
2014-06-03 - 更新:2014-08-19
GoogleMap APIを利用して、座標から住所を取得します。
まず、座標オブジェクトを作成します。
location = new google.maps.LatLng([latitude], [longitude]);
ジオコーダーオブジェクトのインスタンスを生成
geocoder = new google.maps.Geocoder();
google.maps.Geocoderクラスのgeocodeメソッドでリクエストを送信し、返ってきたレスポンスを処理するコールバック関数を指定します。
複数の答えが返ってくる場合があるので、結果は配列になっています。
返ってきた結果のフォーマット済の文字列を取得する例
if(geocoder)
{
geocoder.geocode(
{location: location},
function(geo_result, geo_response)
{
if(geo_response == "OK") {
var tmpadd = "";
tmpadd = geo_result[0].formatted_address;
alert("住所:" + tmpadd);
} else {
alert(geo_response + "\n\n変換できませんでした。");
}
}
);
}








