I just wondered if anyone knew of a simple script available that will do the following:
Load a google map in view, when clicked it displays a marker that will save the lat and long values to a variable?
Does anyone know if something like this already exists in PHP?
Thanks in advance
addListener(myMarker, 'dragend', function(evt){ document. getElementById('current'). innerHTML = '<p>Marker dropped: Current Lat: ' + evt. latLng.
You can add a simple marker to the map at a desired location by instantiating the marker class and specifying the position to be marked using latlng, as shown below.
Perhaps you are looking for something similar to this Latitude-Longitude Finder Tool. The example code is was API v2. Below is trimmed down version of the code using Google Maps API v3:
var latlng = new google.maps.LatLng(51.4975941, -0.0803232);
var map = new google.maps.Map(document.getElementById('map'), {
center: latlng,
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: 'Set lat/lon values for this property',
draggable: true
});
google.maps.event.addListener(marker, 'dragend', function(a) {
console.log(a);
// bingo!
// a.latLng contains the co-ordinates where the marker was dropped
});
Explanation: you must set the draggable
property of the marker to true. You can then hook a callback function to that marker's dragend
event; the new co-ordinates are passed to the function and you can assign them to a JavaScript variable or form field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With