如果你能用PYTHON的話是有免費CLASS可用
https://pypi.org/project/geopy/
PHP可以直接EXEC("your.py");
用法超級簡單,幼稚園等級,免註冊Google * API的KEY
from geopy.geocoders import Nominatim
geolocation = Nominatim(user_agent="geotest")
location = geolocation.reverse("25.046517, 121.460614")
print(location.address)
輸出
思源路112巷, 思源里, 新莊區, 中興里, 30, Taiwan
用
print(location.raw)
可以看到更多資料
{'place_id': 274167592, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 364342772, 'lat': '25.046680148016772', 'lon': '121.46061970783416', 'display_name': '思源路112巷, 思源里, 新莊區, 中興里, 30, Taiwan', 'address': {'road': '思源路112巷', 'neighbourhood': '思源里', 'suburb': '新莊區', 'village': '中興里', 'postcode': '30', 'country': 'Taiwan', 'country_code': 'tw'}, 'boundingbox': ['25.0466468', '25.0466991', '121.460078', '121.4615729']}
這個例子上的座標是我隨意設定的,與任何人無關,請勿到那裡找任何大大啊....
如果你是用 Google Apps Script 的話
https://developers.google.com/apps-script/reference/maps/geocoder#reverseGeocode(Number,Number)
程式碼
function myFunction() {
var response = Maps.newGeocoder().reverseGeocode(25.040854, 121.518549);
console.log(JSON.stringify(response))
for (var i = 0; i < response.results.length; i++) {
var result = response.results[i];
Logger.log('%s: %s, %s', result.formatted_address,
result.geometry.location.lat, result.geometry.location.lng
);
}
}
部分結果
[20-11-18 09:20:19:431 HKT] Logger.log([%s: %s, %s, [No. 12, Zhongshan South Road, Zhongzheng District, Taipei City, Taiwan 100, 25.0409073, 121.5184266]]) [0 seconds]
[20-11-18 09:20:19:431 HKT] Logger.log([%s: %s, %s, [No. 12, Zhongshan South Road, Zhongzheng District, Taipei City, Taiwan 100, 25.0409295, 121.5183387]]) [0 seconds]
[20-11-18 09:20:19:432 HKT] Logger.log([%s: %s, %s, [No. 12, Zhongshan South Road, Zhongzheng District, Taipei City, Taiwan 100, 25.0413061, 121.5184521]]) [0 seconds]
[20-11-18 09:20:19:432 HKT] Logger.log([%s: %s, %s, [100, Taiwan, 台北市中正區東門里, 25.0378259, 121.5212991]]) [0 seconds]
[20-11-18 09:20:19:432 HKT] Logger.log([%s: %s, %s, [Zhongzheng District, Taipei City, Taiwan 100, 25.0421407, 121.5198716]]) [0 seconds]
[20-11-18 09:20:19:432 HKT] Logger.log([%s: %s, %s, [Zhongzheng District, Taipei City, Taiwan 100, 25.0421407, 121.5198716]]) [0 seconds]
[20-11-18 09:20:19:432 HKT] Logger.log([%s: %s, %s, [Taipei City, Taiwan, 25.0329636, 121.5654268]]) [0 seconds]
[20-11-18 09:20:19:432 HKT] Logger.log([%s: %s, %s, [Taipei, Taiwan, 25.0329694, 121.5654177]]) [0 seconds]
[20-11-18 09:20:19:432 HKT] Logger.log([%s: %s, %s, [Taiwan, 23.9036873, 121.0793705]]) [0 seconds]
[20-11-18 09:20:19:432 HKT] Logger.log([%s: %s, %s, [Taiwan, 23.69781, 120.960515]]) [0 seconds]
完整結果
{
"plus_code": {
"compound_code": "2GR9+8C Zhongzheng District, Taipei City, Taiwan",
"global_code": "7QQ32GR9+8C"
},
"results": [{
"formatted_address": "No. 12, Zhongshan South Road, Zhongzheng District, Taipei City, Taiwan 100",
"types": ["street_address"],
"geometry": {
"viewport": {
"southwest": {
"lng": 121.5170776197085,
"lat": 25.03955831970849
},
"northeast": {
"lng": 121.5197755802915,
"lat": 25.0422562802915
}
},
"location": {
"lng": 121.5184266,
"lat": 25.0409073
},
"location_type": "ROOFTOP"
},
"address_components": [{
"types": ["street_number"],
"short_name": "12",
"long_name": "12"
}, {
"types": ["route"],
"short_name": "Zhongshan South Road",
"long_name": "Zhongshan South Road"
}, {
"types": ["administrative_area_level_3", "political"],
"short_name": "Zhongzheng District",
"long_name": "Zhongzheng District"
}, {
"types": ["administrative_area_level_1", "political"],
"short_name": "Taipei City",
"long_name": "Taipei City"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}, {
"types": ["postal_code"],
"short_name": "100",
"long_name": "100"
}],
"plus_code": {
"compound_code": "2GR9+99 Zhongzheng District, Taipei City, Taiwan",
"global_code": "7QQ32GR9+99"
},
"place_id": "ChIJVVyfQHSpQjQRQk60_hK2FUU"
}, {
"formatted_address": "No. 12, Zhongshan South Road, Zhongzheng District, Taipei City, Taiwan 100",
"types": ["street_address"],
"geometry": {
"viewport": {
"southwest": {
"lng": 121.5169897197085,
"lat": 25.03958051970849
},
"northeast": {
"lng": 121.5196876802915,
"lat": 25.0422784802915
}
},
"location": {
"lng": 121.5183387,
"lat": 25.0409295
},
"location_type": "RANGE_INTERPOLATED"
},
"address_components": [{
"types": ["street_number"],
"short_name": "12",
"long_name": "12"
}, {
"types": ["route"],
"short_name": "Zhongshan South Road",
"long_name": "Zhongshan South Road"
}, {
"types": ["administrative_area_level_3", "political"],
"short_name": "Zhongzheng District",
"long_name": "Zhongzheng District"
}, {
"types": ["administrative_area_level_1", "political"],
"short_name": "Taipei City",
"long_name": "Taipei City"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}, {
"types": ["postal_code"],
"short_name": "100",
"long_name": "100"
}],
"place_id": "EkpOby4gMTIsIFpob25nc2hhbiBTb3V0aCBSb2FkLCBaaG9uZ3poZW5nIERpc3RyaWN0LCBUYWlwZWkgQ2l0eSwgVGFpd2FuIDEwMCIaEhgKFAoSCUHrhBJ0qUI0EVCleK65xPMFEAw"
}, {
"formatted_address": "No. 12, Zhongshan South Road, Zhongzheng District, Taipei City, Taiwan 100",
"types": ["route"],
"geometry": {
"viewport": {
"southwest": {
"lng": 121.5171022197085,
"lat": 25.0399573197085
},
"northeast": {
"lng": 121.5198001802915,
"lat": 25.0426552802915
}
},
"bounds": {
"southwest": {
"lng": 121.5182722,
"lat": 25.0407128
},
"northeast": {
"lng": 121.5186302,
"lat": 25.0418998
}
},
"location": {
"lng": 121.5184521,
"lat": 25.0413061
},
"location_type": "GEOMETRIC_CENTER"
},
"address_components": [{
"types": ["street_number"],
"short_name": "12",
"long_name": "12"
}, {
"types": ["route"],
"short_name": "Zhongshan South Road",
"long_name": "Zhongshan South Road"
}, {
"types": ["administrative_area_level_3", "political"],
"short_name": "Zhongzheng District",
"long_name": "Zhongzheng District"
}, {
"types": ["administrative_area_level_1", "political"],
"short_name": "Taipei City",
"long_name": "Taipei City"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}, {
"types": ["postal_code"],
"short_name": "100",
"long_name": "100"
}],
"place_id": "ChIJQeuEEnSpQjQRUKV4rrnE8wU"
}, {
"formatted_address": "100, Taiwan, 台北市中正區東門里",
"types": ["administrative_area_level_4", "political"],
"geometry": {
"viewport": {
"southwest": {
"lng": 121.516652,
"lat": 25.0323165
},
"northeast": {
"lng": 121.5261717,
"lat": 25.0433003
}
},
"bounds": {
"southwest": {
"lng": 121.516652,
"lat": 25.0323165
},
"northeast": {
"lng": 121.5261717,
"lat": 25.0433003
}
},
"location": {
"lng": 121.5212991,
"lat": 25.0378259
},
"location_type": "APPROXIMATE"
},
"address_components": [{
"types": ["administrative_area_level_4", "political"],
"short_name": "東門里",
"long_name": "東門里"
}, {
"types": ["administrative_area_level_3", "political"],
"short_name": "中正區",
"long_name": "中正區"
}, {
"types": ["administrative_area_level_1", "political"],
"short_name": "台北市",
"long_name": "台北市"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}, {
"types": ["postal_code"],
"short_name": "100",
"long_name": "100"
}],
"place_id": "ChIJo6nDanapQjQRNrFmZWw6-uw"
}, {
"formatted_address": "Zhongzheng District, Taipei City, Taiwan 100",
"types": ["administrative_area_level_3", "political"],
"geometry": {
"viewport": {
"southwest": {
"lng": 121.5040875,
"lat": 25.0086658
},
"northeast": {
"lng": 121.537079,
"lat": 25.0499358
}
},
"bounds": {
"southwest": {
"lng": 121.5040875,
"lat": 25.0086658
},
"northeast": {
"lng": 121.537079,
"lat": 25.0499358
}
},
"location": {
"lng": 121.5198716,
"lat": 25.0421407
},
"location_type": "APPROXIMATE"
},
"address_components": [{
"types": ["administrative_area_level_3", "political"],
"short_name": "Zhongzheng District",
"long_name": "Zhongzheng District"
}, {
"types": ["administrative_area_level_1", "political"],
"short_name": "Taipei City",
"long_name": "Taipei City"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}, {
"types": ["postal_code"],
"short_name": "100",
"long_name": "100"
}],
"place_id": "ChIJHS0e0JupQjQRfXn-xB6KGLo"
}, {
"formatted_address": "Zhongzheng District, Taipei City, Taiwan 100",
"types": ["postal_code"],
"geometry": {
"viewport": {
"southwest": {
"lng": 121.5040875,
"lat": 25.0086658
},
"northeast": {
"lng": 121.537079,
"lat": 25.0499358
}
},
"bounds": {
"southwest": {
"lng": 121.5040875,
"lat": 25.0086658
},
"northeast": {
"lng": 121.537079,
"lat": 25.0499358
}
},
"location": {
"lng": 121.5198716,
"lat": 25.0421407
},
"location_type": "APPROXIMATE"
},
"address_components": [{
"types": ["postal_code"],
"short_name": "100",
"long_name": "100"
}, {
"types": ["administrative_area_level_3", "political"],
"short_name": "Zhongzheng District",
"long_name": "Zhongzheng District"
}, {
"types": ["administrative_area_level_1", "political"],
"short_name": "Taipei City",
"long_name": "Taipei City"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}],
"place_id": "ChIJx7yt0ZupQjQRRBldho7jwCc"
}, {
"formatted_address": "Taipei City, Taiwan",
"types": ["administrative_area_level_1", "political"],
"geometry": {
"viewport": {
"southwest": {
"lng": 121.4570603,
"lat": 24.9605084
},
"northeast": {
"lng": 121.6659421,
"lat": 25.2103038
}
},
"bounds": {
"southwest": {
"lng": 121.4570603,
"lat": 24.9605084
},
"northeast": {
"lng": 121.6659421,
"lat": 25.2103038
}
},
"location": {
"lng": 121.5654268,
"lat": 25.0329636
},
"location_type": "APPROXIMATE"
},
"address_components": [{
"types": ["administrative_area_level_1", "political"],
"short_name": "Taipei City",
"long_name": "Taipei City"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}],
"place_id": "ChIJi73bYWusQjQRgqQGXK260bw"
}, {
"formatted_address": "Taipei, Taiwan",
"types": ["colloquial_area", "locality", "political"],
"geometry": {
"viewport": {
"southwest": {
"lng": 121.2826735,
"lat": 24.7900797
},
"northeast": {
"lng": 121.7300824,
"lat": 25.2443731
}
},
"bounds": {
"southwest": {
"lng": 121.2826735,
"lat": 24.7900797
},
"northeast": {
"lng": 121.7300824,
"lat": 25.2443731
}
},
"location": {
"lng": 121.5654177,
"lat": 25.0329694
},
"location_type": "APPROXIMATE"
},
"address_components": [{
"types": ["colloquial_area", "locality", "political"],
"short_name": "Taipei",
"long_name": "Taipei"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}],
"place_id": "ChIJmQrivHKsQjQR4MIK3c41aj8"
}, {
"formatted_address": "Taiwan",
"types": ["establishment", "natural_feature"],
"geometry": {
"viewport": {
"southwest": {
"lng": 120.0277765,
"lat": 21.8966958
},
"northeast": {
"lng": 122.0069052,
"lat": 25.3011502
}
},
"bounds": {
"southwest": {
"lng": 120.0277765,
"lat": 21.8966958
},
"northeast": {
"lng": 122.0069052,
"lat": 25.3011502
}
},
"location": {
"lng": 121.0793705,
"lat": 23.9036873
},
"location_type": "APPROXIMATE"
},
"address_components": [{
"types": ["establishment", "natural_feature"],
"short_name": "Taiwan",
"long_name": "Taiwan"
}, {
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}],
"place_id": "ChIJpcNhK8vVbjQRoH--QrDdIM8"
}, {
"formatted_address": "Taiwan",
"types": ["country", "political"],
"geometry": {
"viewport": {
"southwest": {
"lng": 116.6665,
"lat": 20.5170001
},
"northeast": {
"lng": 123.5021012,
"lat": 26.4545
}
},
"bounds": {
"southwest": {
"lng": 116.6665,
"lat": 20.5170001
},
"northeast": {
"lng": 123.5021012,
"lat": 26.4545
}
},
"location": {
"lng": 120.960515,
"lat": 23.69781
},
"location_type": "APPROXIMATE"
},
"address_components": [{
"types": ["country", "political"],
"short_name": "TW",
"long_name": "Taiwan"
}],
"place_id": "ChIJL1cHXAbzbjQRaVScvwTwEec"
}],
"status": "OK"
}
既然是工作需要
就向主管申請預算
然後用Google Geocoding API就好了
範例如下
Request
=========
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
Response
=========
{
"results" : [
{
"address_components" : [
{
"long_name" : "277",
"short_name" : "277",
"types" : [ "street_number" ]
},
{
"long_name" : "Bedford Avenue",
"short_name" : "Bedford Ave",
"types" : [ "route" ]
},
{
"long_name" : "Williamsburg",
"short_name" : "Williamsburg",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Brooklyn",
"short_name" : "Brooklyn",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Kings",
"short_name" : "Kings",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "11211",
"short_name" : "11211",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA",
"geometry" : {
"location" : {
"lat" : 40.714232,
"lng" : -73.9612889
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 40.7155809802915,
"lng" : -73.9599399197085
},
"southwest" : {
"lat" : 40.7128830197085,
"lng" : -73.96263788029151
}
}
},
"place_id" : "ChIJd8BlQ2BZwokRAFUEcm_qrcA",
"types" : [ "street_address" ]
},
... Additional results[] ...