摘要:Google Geocoding API 應用
小編最近有撰寫一個使用Bing Map的APP,剛好用到Google Geocoding API就上來跟大家分享一下。
Google Geocoding API可以輸入自己的地址,並且可以轉成座標後自動標示於地圖上。
當然也可以透過經緯度轉換為地址,但Google Geocoding API也是有查詢限制的;
每天最多發出 2,500 個地理位置要求 ,Google Maps API for Business 使用者每天最多可執行 100,000 個要求。
Google Geocoding API回傳的的結果有提供JSON以及XML。
如果讀者要使用JSON格式就使用這個:
http://maps.googleapis.com/maps/api/geocode/json?address=台灣台中市三民路三段129號&sensor=false
如果讀者是使用XML格式就使用這個:
http://maps.googleapis.com/maps/api/geocode/xml?address=台灣台中市三民路三段129號&sensor=false
未來讀者要使用的時候,只需要將address=台灣台中市三民路三段129號,改成自已想要的地址就可以得到該地址得資訊。
小編在這邊使用是JSON格式,把該網址貼到瀏覽器上面就會回傳一個JSON格式檔。
{
"results" : [
{
"address_components" : [
{
"long_name" : "129",
"short_name" : "129",
"types" : [ "street_number" ]
},
{
"long_name" : "國立臺中科技大學",
"short_name" : "國立臺中科技大學",
"types" : [ "establishment" ]
},
{
"long_name" : "三民路三段",
"short_name" : "三民路三段",
"types" : [ "route" ]
},
{
"long_name" : "錦平里",
"short_name" : "錦平里",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "北區",
"short_name" : "北區",
"types" : [ "locality", "political" ]
},
{
"long_name" : "台中市",
"short_name" : "台中市",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "台灣",
"short_name" : "TW",
"types" : [ "country", "political" ]
},
{
"long_name" : "404",
"short_name" : "404",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "404台灣台中市北區國立臺中科技大學三民路三段129號",
"geometry" : {
"location" : {
"lat" : 24.1500261,
"lng" : 120.6839536
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 24.1513750802915,
"lng" : 120.6853025802915
},
"southwest" : {
"lat" : 24.14867711970849,
"lng" : 120.6826046197085
}
}
},
"partial_match" : true,
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
之後我們就利用該網址的回傳結果,取得Google Maps上的資訊。