Geocoding過去在WebGIS系列文有介紹過
[Day 8] 自己產製資料-地址定位part1 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天
今天要來看看地址定位的API,我們也把Geocoding限縮在以門牌地址
為主的查詢
來看看幾個商用的Geocoding
Google
Google API要做Geocoding是基於Place API
在Google Cloud Console註冊好一支服務並取得API Key後就可以使用(注意收費方式啊~)
Place Search | Places API | Google Developers
從文件上,可以看到Google Place API能回應的內容還滿豐富的
因為他並不是一個單純的一個Geocoding,他其實是結合Google其他服務(照片、地標等)的查詢
順便可以查地址而已
簡單測試一下一個都市區很常見的地址(如有雷同純屬巧合)
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=台北市南港區忠孝東路七段576號&inputtype=textquery&fields=formatted_address,name,rating,opening_hours,geometry&key=API_KEY
結果
{
"candidates": [
{
"formatted_address": "115台灣台北市南港區忠孝東路七段576號",
"geometry": {
"location": {
"lat": 25.0526151,
"lng": 121.6136186
},
"viewport": {
"northeast": {
"lat": 25.05406552989272,
"lng": 121.6149543798927
},
"southwest": {
"lat": 25.05136587010728,
"lng": 121.6122547201072
}
}
},
"name": "115台北市南港區忠孝東路七段576號"
}
],
"status": "OK"
}
TomTom
TomTom有Geocoding API,可以找到文件如下
https://developer.tomtom.com/search-api/search-api-documentation-geocoding/geocode
跟Google 一樣,雖然是Geocoding,回應來的東西不只我們上面定義的地址
而已
但一樣,我們測試一樣的地址
https://api.tomtom.com/search/2/geocode/台北市南港區忠孝東路七段576號.json?countrySet=TWN&key=API_KEY
結果:
{
"summary": {
"query": "台北市南港區忠孝東路七段576號",
"queryType": "NON_NEAR",
"queryTime": 155,
"numResults": 1,
"offset": 0,
"totalResults": 18555,
"fuzzyLevel": 2
},
"results": [
{
"type": "Point Address",
"id": "TW/PAD/p0/2804942",
"score": 26.36517,
"address": {
"streetNumber": "576",
"streetName": "忠孝東路七段",
"municipalitySubdivision": "南港區, nan gang qu",
"municipality": "臺北市, 台北市, tai bei shi",
"countrySubdivision": "台北市, tai bei shi",
"postalCode": "115",
"extendedPostalCode": "11561",
"countryCode": "TW",
"country": "Taiwan",
"countryCodeISO3": "TWN",
"freeformAddress": "台北市 南港區 忠孝東路七段 576",
"localName": "南港區"
},
"position": {
"lat": 25.05265,
"lon": 121.61357
},
"viewport": {
"topLeftPoint": {
"lat": 25.05355,
"lon": 121.61258
},
"btmRightPoint": {
"lat": 25.05175,
"lon": 121.61456
}
},
"entryPoints": [
{
"type": "main",
"position": {
"lat": 25.0528,
"lon": 121.61354
}
}
]
}
]
}
Here
Here 一樣可以找到文件有Geocoding API
Resources and Parameters - Geocoder API - HERE Developer
我們測試同一段地址
https://geocoder.api.here.com/6.2/geocode.json?app_id=APP_ID&app_code=APP_CODE&searchtext=台北市南港區忠孝東路七段576號
結果:
{
"Response": {
"MetaInfo": {
"Timestamp": "2019-09-21T15:07:31.540+0000"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
"Relevance": 1,
"MatchLevel": "houseNumber",
"MatchQuality": {
"City": 1,
"District": 1,
"Street": [
1
],
"HouseNumber": 1
},
"MatchType": "pointAddress",
"Location": {
"LocationId": "NT_6aXvBb1I8wsCVgRBKOg7zC_1cjNon5n",
"LocationType": "point",
"DisplayPosition": {
"Latitude": 25.05269,
"Longitude": 121.61361
},
"NavigationPosition": [
{
"Latitude": 25.05285,
"Longitude": 121.61359
}
],
"MapView": {
"TopLeft": {
"Latitude": 25.0538142,
"Longitude": 121.6123691
},
"BottomRight": {
"Latitude": 25.0515658,
"Longitude": 121.6148509
}
},
"Address": {
"Label": "臺灣115台北市南港區忠孝東路七段576號",
"Country": "TWN",
"County": "台北市",
"City": "台北市",
"District": "南港區",
"Street": "忠孝東路七段",
"HouseNumber": "576號",
"PostalCode": "115",
"AdditionalData": [
{
"value": "臺灣",
"key": "CountryName"
},
{
"value": "台北市",
"key": "CountyName"
}
]
}
}
}
]
}
]
}
}
基本測試給的地址算是大地標,因此都查得到
因為台灣地址常常在變,而且地址資料的搜集也耗時費力
實務上常常偶爾也會有大量Geocoding的時候
而也偶爾會遇到比較難的地址(送餐或叫車軟體的痛..)
各家API有時候也會有些問題
大家在使用的時候,不妨先測試看看...
Place Searches | Maps JavaScript API | Google Developers
ps.以上並非Geocoding API產品線,我測試了一下搜尋品質跟call API不一樣,建議還是實際call API