add accuracy circle
This commit is contained in:
parent
25c109504f
commit
1aac4e1c15
@ -5,6 +5,7 @@ var endLat = '';
|
|||||||
var endLon = '';
|
var endLon = '';
|
||||||
var startLat = 49.8955663;
|
var startLat = 49.8955663;
|
||||||
var startLon = 10.886907899999999;
|
var startLon = 10.886907899999999;
|
||||||
|
var accuracy = 1;
|
||||||
document.addEventListener('DOMContentLoaded', loadData);
|
document.addEventListener('DOMContentLoaded', loadData);
|
||||||
document.addEventListener('DOMContentLoaded', resizeMap);
|
document.addEventListener('DOMContentLoaded', resizeMap);
|
||||||
document.addEventListener('DOMContentLoaded', getPos);
|
document.addEventListener('DOMContentLoaded', getPos);
|
||||||
@ -34,10 +35,9 @@ function generateMap(streets) {
|
|||||||
if (streets.length > 0) {
|
if (streets.length > 0) {
|
||||||
endLon = streets[0]['lon'];
|
endLon = streets[0]['lon'];
|
||||||
endLat = streets[0]['lat'];
|
endLat = streets[0]['lat'];
|
||||||
console.log(endLat);
|
|
||||||
var map = L.map('map').setView([endLat, endLon], zoomlevel);
|
var map = L.map('map').setView([endLat, endLon], zoomlevel);
|
||||||
|
|
||||||
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
@ -47,6 +47,12 @@ function generateMap(streets) {
|
|||||||
L.marker([startLat, startLon]).addTo(map)
|
L.marker([startLat, startLon]).addTo(map)
|
||||||
.bindPopup('You are here!')
|
.bindPopup('You are here!')
|
||||||
.openPopup();
|
.openPopup();
|
||||||
|
L.circle([startLat, startLon], {
|
||||||
|
color: '#6b6b6b',
|
||||||
|
fillColor: '#6b6b6b',
|
||||||
|
fillOpacity: 0.4,
|
||||||
|
radius: accuracy
|
||||||
|
}).addTo(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -62,15 +68,17 @@ function resizeMap() {
|
|||||||
function getPos() {
|
function getPos() {
|
||||||
if (navigator.geolocation) {
|
if (navigator.geolocation) {
|
||||||
var geo_option = {
|
var geo_option = {
|
||||||
enableHighAccuracy: true,
|
enableHighAccuracy: true
|
||||||
}
|
};
|
||||||
navigator.geolocation.getCurrentPosition(function (position) {
|
navigator.geolocation.getCurrentPosition(function (position) {
|
||||||
console.log(position);
|
console.log(position);
|
||||||
startLat = position.coords.latitude;
|
startLat = position.coords.latitude;
|
||||||
startLon = position.coords.longitude;
|
startLon = position.coords.longitude;
|
||||||
|
accuracy = position.coords.accuracy;
|
||||||
|
console.log('Lat: ' + startLat + ' Lon: ' + startLon + ' Acc: ' + accuracy)
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
console.log(err.code)
|
console.log(err.code);
|
||||||
console.log(err.message)
|
console.log(err.message);
|
||||||
}, geo_option)
|
}, geo_option)
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('map').innerHTML('Geolocation not available')
|
document.getElementById('map').innerHTML('Geolocation not available')
|
||||||
|
|||||||
Reference in New Issue
Block a user