Código:
<!DOCTYPE html> <html> <head> <title>Simple Map</title> <meta name="viewport" content="initial-scale=1.0"> <meta charset="utf-8"> <style> /* Always set the map height explicitly to define the size of the div * element that contains the map. */ #map { height: 600px; width: 800px; } /* Optional: Makes the sample page fill the window. */ html, body { height: 100%; margin: 0; padding: 0; } </style> </head> <body> <div id="map"></div> <script> function openInfoWindow(marker) { var markerLatLng = marker.getPosition(); infoWindow.setContent([ 'latitud: ', markerLatLng.lat(), ', longitud: ', markerLatLng.lng(), '' ].join('')); infoWindow.open(map, marker); } function guardar(marker){ var markerLatLng = marker.getPosition(); getElementById('lat').value = markerLatLng.lat(); getElementById('lng').value = markerLatLng.lng(); } function initMap() { var myLatLng = {lat: 8.5989, lng: -71.141196}; var map = new google.maps.Map(document.getElementById('map'), { zoom: 18, center: myLatLng }); infoWindow = new google.maps.InfoWindow(); var marker = new google.maps.Marker({ position: myLatLng, map: map, draggable: true, title: 'Hello World!' }); google.maps.event.addListener(marker, 'mouseup', function(){ openInfoWindow(marker); }); } </script> <form id="mapCenterForm"> Lat: <span type="text" id="lat" /> <br /> Lng: <span type="text" id="lng" /> <br /> </form> <br /> <div id="map-canvas"></div> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB5N4eJjRV1fpJUPe5NS5D6mZ3G4xo7j6U&callback=initMap" async defer></script> </body> </html>
el detalle es que necesito pasar las variables de latitud a longitud a otra variable y mostrarla, tambien pasarla al controlador,yo para capturarlas y mostrarlas utilice los span y los getElementbyid pero no me muestra nada, si me pudiesen ayudar se los agradeceria mucho...