Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created January 1, 2016 06:52
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 chuck0523/dbc84ee9993fca1615ff to your computer and use it in GitHub Desktop.
Save chuck0523/dbc84ee9993fca1615ff to your computer and use it in GitHub Desktop.
// 位置情報取得
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