Skip to content

Instantly share code, notes, and snippets.

@letswritetw
Last active July 26, 2022 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letswritetw/9e7c95bd0da71c4cdd7dff00f7c5744e to your computer and use it in GitHub Desktop.
Save letswritetw/9e7c95bd0da71c4cdd7dff00f7c5744e to your computer and use it in GitHub Desktop.
leaflet-osm-basic
// 跟使用者要位置
function successGPS(position) {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
center = [lat, lng];
// 接著寫確認了座標後要執行的事
};
function errorGPS() {
window.alert('無法判斷您的所在位置,無法使用此功能。預設地點將為 台北市動物園');
// 接著寫使用者「封鎖」位置資訊請求後要執行的事
}
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successGPS, errorGPS);
} else {
window.alert('您的裝置不具備GPS,無法使用此功能');
// 接著寫使用者裝置不支援位置資訊時要執行的事
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment