Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda