輸入地址取得地理座標- Google Geocoding API

將地址轉換為經緯度的程序被稱為地理編碼(Geocoding),要取得某地址的經緯度,也是可以仰賴 google 大神,參考這個網址
http://maps.googleapis.com/maps/api/geocode/json?address=欲查詢的地址&sensor=false

在address後面輸入地址,google會回傳一個json格式的資料。

比如說我輸入一個地址,回傳了這樣的資料,找到location下的經緯度就可以了。
  1. "geometry" : {   
  2.             "location" : {   
  3.                "lat" : 25.04385720,   
  4.                "lng" : 121.52881520   
  5.             },   
  6.             "location_type" : "ROOFTOP",   
  7.             "viewport" : {   
  8.                "northeast" : {   
  9.                   "lat" : 25.04520618029150,   
  10.                   "lng" : 121.5301641802915   
  11.                },   
  12.                "southwest" : {   
  13.                   "lat" : 25.04250821970850,   
  14.                   "lng" : 121.5274662197085   
  15.                }   
  16.             }   
  17.          },  

有興趣可以看看這個的地址是哪邊。

留言