Soy nuevo en Stackoverflow, JavaScript y Google Map API. El problema es que actualmente obtengo la ubicación actual del usuario con el siguiente código, pero ¿cómo puedo devolver el valor de Latlng de esto y usarlo en otros lugares en el script, como al hacer una llamada para directionsService ?
function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); //console.log("location--Yes"); } else { alert("Geolocation is not supported by this browser."); } } function showPosition(position) { var lat = position.coords.latitude; var lng = position.coords.longitude; var latlng = new google.maps.LatLng(lat, lng); const marker = new google.maps.Marker({ position: latlng, visible: true, map: map }); marker.setMap(map); //console.log("marker should display"); //return latlng; }¡Gracias por la ayuda!