Extracting Structured Address Information-GoogleMaps/API/doc/GeocoderExamples/02-ExtractingStructuredAddressInformation-N☆E 学習帳

[ リロード ]   [ ソース ]  [ トップ | 一覧 | 単語検索 | 最新 | バックアップ | ヘルプ ]

Counter: 3741, today: 3, yesterday: 1

Extracting Structured Address Information

http://www.google.com/apis/maps/docu­mentation/

Version2 (2006.6 新規

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.

  • Status
    • request -- The request type. In this case, it is always geocode.
    • code -- A response code (similar to HTTP status codes) indicating whether the geocode request was successful or not. See the full list of status codes.
  • Placemark -- Multiple placemarks may be returned if the geocoder finds multiple matches.
    • address -- A nicely formatted and properly capitalized version of the address.
    • AddressDetails -- The address formatted as xAL, or eXtensible Address Language, an international standard for address formatting.
      • Accuracy -- An attribute indicating how accurately we were able to geocode the given address. See a list of possible values. (2006.7追加)
    • Point -- A point in 3D space.
      • coordinates -- The longitude, latitude, and altitude of the address. In this case, the altitude is always set to 0.

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 )