← Back to list

[Web API] 如何使用 window.navigator.geolocation 取得使用者的現在位置

依照 MDN 的說明與 Web API 的規範,要在瀏覽器使用 geo Location 會有三個階段分別是「抓資料」,「開始監聽」,「停止」,且必須是 https

kueiapp.com · 2025-09-17 06:27 · 0 claps · 0.2 min read
#geolocation #web #html5
Open on Medium ↗
Wiki topics: 🌐 · Web Development

[Web API] 如何使用 window.navigator.geolocation 取得使用者的現在位置

依照 MDN 的說明與 Web API 的規範,要在瀏覽器使用 geo Location 會有三個階段分別是「抓資料」,「開始監聽」,「停止」,且必須是 https

  • checkGeolocation()
  • startWatchingGeolocation()
  • endWatchingGeolocation()

對應的 Web API 個別是 navigator.geolocation 下的這三個

  • navigator.geolocation.getCurrentPosition(handleSuccess, handleError, gpsOption)
  • navigator.geolocation.watchPosition(handleSuccess, handleError, options)
  • navigator.geolocation.clearWatch(state.watchingId)

全文連結:https://blog.kueiapp.com/zh/programming-tw/web-api-use-window-navigator-geolocation-to-get-users-current-position/


메타데이터
post_id
8fac11a4b15b
slug
web-api-如何使用-window-navigator-geolocation-取得使用者的現在位置-8fac11a4b15b
url
https://medium.com/@kueiapp/web-api-%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-window-navigator-geolocation-%E5%8F%96%E5%BE%97%E4%BD%BF%E7%94%A8%E8%80%85%E7%9A%84%E7%8F%BE%E5%9C%A8%E4%BD%8D%E7%BD%AE-8fac11a4b15b
canonical_url
https://medium.com/@kueiapp/web-api-%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-window-navigator-geolocation-%E5%8F%96%E5%BE%97%E4%BD%BF%E7%94%A8%E8%80%85%E7%9A%84%E7%8F%BE%E5%9C%A8%E4%BD%8D%E7%BD%AE-8fac11a4b15b
author_url
https://medium.com/@kueiapp
status
ok
fetched_at
2026-07-17 11:39:37