因某些原因作一些地圖相關桯式,但只有地址沒有經緯度時,就很麻煩,還好 Google 有提供類似的服務,地址轉經緯度的 JSON
用自已的地址取代下面中地址的部份,就可以得到地址的 JSON 了.
http://maps.googleapis.com/maps/api/geocode/json?address=新北市平溪區十分街51&sensor=false
得到
{
"results" : [
{
"address_components" : [
{
"long_name" : "51",
"short_name" : "51",
"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" : "226",
"short_name" : "226",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "226台灣新北市平溪區十分火車站十分街51號",
"geometry" : {
"location" : {
"lat" : 25.04115320,
"lng" : 121.7751630
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 25.04250218029150,
"lng" : 121.7765119802915
},
"southwest" : {
"lat" : 25.03980421970850,
"lng" : 121.7738140197085
}
}
},
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
=======================================================
也可以做反向查詢
如:
http://maps.googleapis.com/maps/api/geocode/json?latlng=25.0420118,121.5655313&sensor=true_or_false
就會輸出:
{
"results" : [
{
"address_components" : [
{
"long_name" : "157",
"short_name" : "157",
"types" : [ "street_number" ]
},
{
"long_name" : "基隆路一段",
"short_name" : "基隆路一段",
"types" : [ "route" ]
},
{
"long_name" : "興雅里",
"short_name" : "興雅里",
"types" : [ "administrative_area_level_4", "political" ]
},
{
"long_name" : "信義區",
"short_name" : "信義區",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "台北市",
"short_name" : "台北市",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "台灣",
"short_name" : "TW",
"types" : [ "country", "political" ]
},
{
"long_name" : "110",
"short_name" : "110",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "110台灣台北市信義區基隆路一段157號",
"geometry" : {
"location" : {
"lat" : 25.042092,
"lng" : 121.565375
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 25.0434409802915,
"lng" : 121.5667239802915
},
"southwest" : {
"lat" : 25.0407430197085,
"lng" : 121.5640260197085
}
}
},
"place_id" : "ChIJd_3Yqr6rQjQRqF3njZufXy4",
"types" : [ "street_address" ]
},
{
"address_components" : [
{
"long_name" : "臺北",
"short_name" : "臺北",
"types" : [ "colloquial_area", "locality", "political" ]
},
{
"long_name" : "台灣",
"short_name" : "TW",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "台灣臺北",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 25.2443731,
"lng" : 121.7300824
},
"southwest" : {
"lat" : 24.7900797,
"lng" : 121.2826735
}
},
"location" : {
"lat" : 25.0329694,
"lng" : 121.5654177
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 25.2443731,
"lng" : 121.7300824
},
"southwest" : {
"lat" : 24.7900797,
"lng" : 121.2826735
}
}
},
"place_id" : "ChIJmQrivHKsQjQR4MIK3c41aj8",
"types" : [ "colloquial_area", "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "興雅里",
"short_name" : "興雅里",
"types" : [ "administrative_area_level_4", "political" ]
},
{
"long_name" : "信義區",
"short_name" : "信義區",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "台北市",
"short_name" : "台北市",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "台灣",
"short_name" : "TW",
"types" : [ "country", "political" ]
},
{
"long_name" : "110",
"short_name" : "110",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "110台灣台北市信義區興雅里",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 25.043718,
"lng" : 121.5703302
},
"southwest" : {
"lat" : 25.0390649,
"lng" : 121.5634124
}
},
"location" : {
"lat" : 25.0408315,
"lng" : 121.5676828
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 25.043718,
"lng" : 121.5703302
},
"southwest" : {
"lat" : 25.0390649,
"lng" : 121.5634124
}
}
},
"place_id" : "ChIJR_3o87urQjQRPFmSFxOG9tU",
"types" : [ "administrative_area_level_4", "political" ]
},
{
"address_components" : [
{
"long_name" : "信義區",
"short_name" : "信義區",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "台北市",
"short_name" : "台北市",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "台灣",
"short_name" : "TW",
"types" : [ "country", "political" ]
},
{
"long_name" : "110",
"short_name" : "110",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "110台灣台北市信義區",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 25.0493106,
"lng" : 121.5920455
},
"southwest" : {
"lat" : 25.0081179,
"lng" : 121.5525867
}
},
"location" : {
"lat" : 25.0287024,
"lng" : 121.5769572
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 25.0493106,
"lng" : 121.5920455
},
"southwest" : {
"lat" : 25.0081179,
"lng" : 121.5525867
}
}
},
"place_id" : "ChIJxUN17K2rQjQRzThIo3q9jUA",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"address_components" : [
{
"long_name" : "110",
"short_name" : "110",
"types" : [ "postal_code" ]
},
{
"long_name" : "信義區",
"short_name" : "信義區",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "台北市",
"short_name" : "台北市",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "台灣",
"short_name" : "TW",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "110台灣台北市信義區",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 25.0493106,
"lng" : 121.5920455
},
"southwest" : {
"lat" : 25.0081179,
"lng" : 121.5525867
}
},
"location" : {
"lat" : 25.0287024,
"lng" : 121.5769572
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 25.0493106,
"lng" : 121.5920455
},
"southwest" : {
"lat" : 25.0081179,
"lng" : 121.5525867
}
}
},
"place_id" : "ChIJLdKG7K2rQjQReg7CzPISXOg",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "台北市",
"short_name" : "台北市",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "台灣",
"short_name" : "TW",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "台灣台北市",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 25.2103038,
"lng" : 121.6659421
},
"southwest" : {
"lat" : 24.9605084,
"lng" : 121.4570603
}
},
"location" : {
"lat" : 25.0329636,
"lng" : 121.5654268
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 25.2103038,
"lng" : 121.6659421
},
"southwest" : {
"lat" : 24.9605084,
"lng" : 121.4570603
}
}
},
"place_id" : "ChIJi73bYWusQjQRgqQGXK260bw",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "台灣",
"short_name" : "TW",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "台灣",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 26.3836884,
"lng" : 123.4934282
},
"southwest" : {
"lat" : 20.5862202,
"lng" : 116.7118602
}
},
"location" : {
"lat" : 23.69781,
"lng" : 120.960515
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 25.2996232,
"lng" : 122.0071612
},
"southwest" : {
"lat" : 21.8066129,
"lng" : 120.0350435
}
}
},
"place_id" : "ChIJL1cHXAbzbjQRaVScvwTwEec",
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}
文章標籤
全站熱搜
