Created
January 1, 2016 06:52
-
-
Save chuck0523/dbc84ee9993fca1615ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 位置情報取得 | |
var lat, lng; | |
function geolocationSuccess(position) { | |
lat = position.coords.latitude; | |
lng = position.coords.longitude; | |
} | |
function geolocationError(error) { | |
var errorMessage = { | |
0: "原因不明のエラーが発生しました…。" , | |
1: "位置情報の取得が許可されませんでした…。" , | |
2: "電波状況などで位置情報が取得できませんでした…。" , | |
3: "位置情報の取得に時間がかかり過ぎてタイムアウトしました…。" , | |
} ; | |
console.log( errorMessage[error.code] ) ; | |
} | |
var geoOptions = { | |
"enableHighAccuracy": false , | |
"timeout": 8000 , | |
"maximumAge": 5000 | |
}; | |
if(!navigator.geolocation) { | |
console.log('あなたの端末では、現在位置を取得できません。'); | |
} else { | |
navigator.geolocation.getCurrentPosition( | |
geolocationSuccess, geolocationError, geoOptions | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment