I am currently working with the Google Maps API. The map displays the latitude and longitude when a mouse click event occurs. My next step is to add a Google marker to the map. Below is my JavaScript code snippet:
<script>
function initMap() {
var myLatlng = {lat: 23.133899799999995, lng: 14.812842999999999};
var map = new google.maps.Map(
document.getElementById('map'), {zoom: 16, center: myLatlng});
// Create the initial InfoWindow.
var infoWindow = new google.maps.InfoWindow(
{content: 'Click the map to get Lat/Lng!', position: myLatlng});
infoWindow.open(map);
// Configure the click listener.
map.addListener('click', function(mapsMouseEvent) {
// Close the current InfoWindow.
infoWindow.close();
// Create a new InfoWindow.
infoWindow = new google.maps.InfoWindow({position: mapsMouseEvent.latLng});
infoWindow.setContent(mapsMouseEvent.latLng.toString());
infoWindow.open(map);
//Display latitude and longitude on the webpage
var l =mapsMouseEvent.latLng.toString();
document.getElementById("latlng").innerHTML=l;
});
}
</script>