2012-05-23 24 views
0

我使用這個名爲Geocoder的寶石,它是Ruby on Rails的一部分。您可以選擇使用哪種地理編碼服務,並選擇Google地圖。現在它在高級地理編碼部分陳述,如果我熟悉地理編碼服務,我可以在我的數據庫(如城市,州,國家等)中實際解析並獲取更多數據。Google地圖可以將我的其他地址的內容像城市,州和國家一樣拿出來嗎?

我的問題是,我可以在哪裏看到Google可以爲我解析的所有內容?我想在我的數據庫中添加更多信息,例如省,縣等。我在哪裏看?

回答

2

https://developers.google.com/maps/documentation/geocoding/

檢查了一些此頁面上的樣品JSON/XML輸出。正如你所看到的,你可以得到街道地址,郵政編碼,地區,城市,國家,地區和任何其他可用的信息。

{ 
    "results" : [ 
     { 
     "address_components" : [ 
      { 
       "long_name" : "1600", 
       "short_name" : "1600", 
       "types" : [ "street_number" ] 
      }, 
      { 
       "long_name" : "Amphitheatre Pkwy", 
       "short_name" : "Amphitheatre Pkwy", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Mountain View", 
       "short_name" : "Mountain View", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Santa Clara", 
       "short_name" : "Santa Clara", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "California", 
       "short_name" : "CA", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "United States", 
       "short_name" : "US", 
       "types" : [ "country", "political" ] 
      }, 
      { 
       "long_name" : "94043", 
       "short_name" : "94043", 
       "types" : [ "postal_code" ] 
      } 
     ], 
     "formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", 
     "geometry" : { 
      "location" : { 
       "lat" : 37.42291810, 
       "lng" : -122.08542120 
      }, 
      "location_type" : "ROOFTOP", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 37.42426708029149, 
        "lng" : -122.0840722197085 
       }, 
       "southwest" : { 
        "lat" : 37.42156911970850, 
        "lng" : -122.0867701802915 
       } 
      } 
     }, 
     "types" : [ "street_address" ] 
     } 
    ], 
    "status" : "OK" 
}