http://www.google.com/apis/maps/documentation/
If you would like to access structured information about an address, GClientGeocoder also provides a getLocations method that returns a JSON object consisting of the following information.
Accuracy について (2006.7追加)
GoogleMaps API Blog より
Value | Description |
---|---|
0 | Unknown location. |
1 | Country level accuracy. |
2 | Region (state, province, prefecture, etc.) level accuracy. |
3 | Sub-region (county, municipality, etc.) level accuracy. |
4 | Town (city, village) level accuracy. |
5 | Post code (zip code) level accuracy. |
6 | Street level accuracy. |
7 | Intersection level accuracy. |
8 | Address level accuracy. |
Here we show the JSON object returned by the geocoder for the address of Google's headquarters.
{
name: "1600 Amphitheatre Parkway, Mountain View, CA, USA",
Status: {
code: 200,
request: "geocode"
},
Placemark: [
{
address: "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
AddressDetails: {
Country: {
CountryNameCode: "US",
AdministrativeArea: {
AdministrativeAreaName: "CA",
SubAdministrativeArea: {
SubAdministrativeAreaName: "Santa Clara",
Locality: {
LocalityName: "Mountain View",
Thoroughfare: {
ThoroughfareName: "1600 Amphitheatre Pkwy"
},
PostalCode: {
PostalCodeNumber: "94043"
}
}
}
}
}
"Accuracy": 8 (2006.7追加)
},
Point: {
coordinates: [-122.083739, 37.423021, 0]
}
}
]
}
In this example, we use the getLocations method to geocode addresses, and extract the nicely formatted version of the address and the two-letter country from the JSON and display it in the info window.
var map;
var geocoder;
function addAddressToMap(response) {
map.clearOverlays();
if (!response || response.Status.code != 200) {
alert("\"" + address + "\" not found");
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(place.address + '<br>' +
'<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
}
}
以下のような記述で、上記コールバック関数を呼び出す。
geocoder = new GClientGeocoder();
geocoder.getLocations( "東京都千代田区大手町1-1-1", addAddressToMap )