Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
Google map API navigator.geolocation.getCurrentPosition(showPosition). How to get latlng values out of function

I am new to Stackoverflow, JavaScript and Google Map API. The issue is I am currently getting user current location with below code but how can I return the Latlng value from this and use it in other places in script like in making call for 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;
    }

Thanks for help!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda