Created
July 25, 2014 05:57
-
-
Save hiro-matsuno/45cf2cac9736fd8a6f86 to your computer and use it in GitHub Desktop.
位置情報自動取得してOpenStreetMap表示
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
//位置情報自動取得でマーカーを表示 | |
navigator.geolocation.getCurrentPosition(function(pos){ | |
//緯度・軽度の取得 | |
lat = pos.coords.latitude; | |
lon = pos.coords.longitude; | |
//マーカーの追加 | |
var markers = new OpenLayers.Layer.Markers("Markers"); | |
map.addLayer(markers); | |
//マーカーの設定 | |
var marker = new OpenLayers.Marker( | |
new OpenLayers.LonLat(lon,lat) | |
.transform( | |
new OpenLayers.Projection("EPSG:4326"), | |
new OpenLayers.Projection("EPSG:900913") | |
) | |
); | |
//マーカーの追加 | |
markers.addMarker(marker); | |
},function(e){ | |
alert('位置情報取得できませんでした。'); | |
}, | |
{"enableHighAccuracy":true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment