29 lines
956 B
JavaScript
29 lines
956 B
JavaScript
var mymap = L.map('map').setView([51.505, -0.09], 13);
|
|
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
|
|
attribution: 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
|
|
maxZoom: 18,
|
|
id: 'mapbox/streets-v11',
|
|
tileSize: 512,
|
|
zoomOffset: -1,
|
|
accessToken: 'pk.eyJ1IjoidW5jbGVzYW11bHVzIiwiYSI6ImNrbXVmanF1bzEwd2Mybm82Nzlobm42bHAifQ.fKY7fUnY-MpzZUcseao0zg'
|
|
}).addTo(mymap);
|
|
|
|
var marker = L.marker([0, 0], draggable=true).addTo(mymap);
|
|
|
|
var LatLng = marker.getLatLng();
|
|
|
|
let coordinates_input = document.getElementById('latlng');
|
|
|
|
|
|
|
|
function onMapClick(e) {
|
|
marker.setLatLng(e.latlng);
|
|
LatLng = marker.getLatLng();
|
|
// console.log(LatLng);
|
|
lat = LatLng['lat'];
|
|
lng = LatLng['lng'];
|
|
coordinates_input.value = lat + ', ' + lng;
|
|
}
|
|
|
|
mymap.on('click', onMapClick);
|