Created
March 26, 2015 06:20
-
-
Save KMR-zoar/89e8db813b6439f037bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 myIcon = L.icon({ | |
iconUrl: 'img/here.png', | |
iconSize: [32, 32], | |
}); | |
//マーカーのセット | |
var myMarker; | |
function set_my_position() { | |
//lock_optは gnss.js で宣言している | |
var GNSS_my_position = navigator.geolocation.watchPosition(mypositionok, mypositionng, lock_opt); | |
function mypositionok(position) { | |
if (myMarker) { | |
myMarker.removeFrom(map); | |
} | |
myMarker = L.marker( | |
[position.coords.latitude, position.coords.longitude], | |
{ icon: myIcon } | |
); | |
myMarker.addTo(map); | |
}; | |
//位置情報が取得できなかった場合の処理 | |
function mypositionng() { | |
window.alert("位置情報を利用できません"); | |
}; | |
}; | |
//マップに自己位置表示用のボタンを追加する | |
var my_posision_button = L.control({ position: 'topright' }); | |
my_posision_button.onAdd = function (map) { | |
var div = L.DomUtil.create('div', 'my_posision'); | |
div.innerHTML = '<input value="自己位置を表示する" type="button" onclick="set_my_position();" />' | |
return div; | |
}; | |
my_posision_button.addTo(map); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment