Sean's Note: How to get place and wheather information by latitude and longitude

2014年4月29日 星期二

How to get place and wheather information by latitude and longitude

How to get place information?


我們可以用 Facebook API 和 Foursquare API 來取得附近地點的資訊。

這裡主要介紹怎麼使用 Foursquare API,Foursquare 是一間提供社群服務的網站公司,

其所提供的 API目前是屬於免費的。

部分的版權說明:

Access to the API is currently provided for free, but Foursquare reserves the right to charge for access to the API in the future, at its sole discretion. If we do charge a fee for using the API or any feature thereof, you do not have any obligation to continue to use the API or the applicable feature.”

詳細的版權說明可參考: https://foursquare.com/legal/api/platformpolicy

使用步驟如下:
  1. 先到 Foursquare API 註冊一個帳號。
  2. 登入後,點選 My Apps -> CREATE A NEW APP,建立並填寫 app 的相關資訊。
  3. 建立完成後,會得到一組 Client IDClient Secret
  4. 接著我們只要送出一個 HTTPS request:
    https://api.foursquare.com/v2/venues/search?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&v=20140430&ll=24.983163,121.536084
  5. 傳回的 response 就是附近地點啦!
    以上面的 request 為例,第一個回傳的地點就是 “XXX 燒臘小館”,
    回傳的資訊還包含了該地點的 phone, address, latitude, longitude, distance(36m), category name(Asian Restaurant) 等。
Note: Foursquare API 在中國可使用。

How to get weather information?


我們可以用 Weather Underground 所提供的 Weather API 來取得天氣資訊。

Weather Underground 是一間提供全球氣象資訊的網站公司,

其所提供的 API 根據流量來決定費用。

部分的版權說明:

“(a.)KEY; MONITORING. There is a daily limit and minute rate limit to the number of requests that can be made to the API for free. You may exceed this threshold only if you are or become a fee paying subscriber. WUL will monitor your daily usage of the API to determine if you have exceeded the free-use threshold by using an application programming interface key (the “Key”). Refer to the “Key Settings” page for product pricing, package features, and rate limit levels.”

詳細的版權說明可參考: http://www.wunderground.com/weather/api/d/terms.html

使用步驟如下:
  1. 先到 Weather API 註冊一個帳號。
  2. 登入後,點選 Key Settings,先選擇服務方案,再填寫 app 的相關資訊。
  3. 建立完成後,會得到一組 Key ID
  4. 接著我們只要送出一個 HTTP request:
    http://api.wunderground.com/api/69f520a20f42ecd9/conditions/settings/lang:TW/q/24.983163,121.536084.json
    (69f520a20f42ecd9 為官網提供的測試 ID 可直接使用)
  5. 傳回的 response 就是詳細的天氣資訊啦!
    以上面的 request 為例,會回傳微雨(weather)、21.4(temp_c)、東北偏東(wind_dir)、
    85%(relative_humidity) 等資訊。


沒有留言:

張貼留言