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

264
Visualizações
How to import data from javascript to html table

I have created a project that when the page opens, it asks the user to accept his location. When the user accepts, a google maps window opens, displaying the user's current location as well as the coordinates:

enter image description here

I want the coordinates to be displayed in an html table next to the google maps window, something similar or the same as this below:

enter image description here

How can I achieve this? I am a begginer in javascript and I need help. Thank you!!!

I will post my javascript code in case it's needed:

// SHOW COORDINATES
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (p) {
        var LatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
        var mapOptions = {
            center: LatLng,
            zoom: 13,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
        var marker = new google.maps.Marker({
            position: LatLng,
            map: map,
            title: "<div style = 'height:60px;width:200px'><b>Your location:</b><br />Latitude: " + p.coords.latitude + "<br />Longitude: " + p.coords.longitude
        });
        google.maps.event.addListener(marker, "click", function (e) {
            var infoWindow = new google.maps.InfoWindow();
            infoWindow.setContent(marker.title);
            infoWindow.open(map, marker);
        });
    });
} else {
    alert('Geo Location feature is not supported in this browser.');
}

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could create a table element and append it to document.body :

// SHOW COORDINATES
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (p) {
        let table = document.createElement("table");
        table.innerHTML = "<tr><th>Latitude</th><th>Longitude</th></tr><tr><td>" + p.coords.latitude + "</td><td>" + p.coords.longitude + "</td></tr>";
        document.body.appendChild(table);
    });
} else {
    console.log('Geo Location feature is not supported in this browser.');
}

about 4 years ago · Juan Pablo Isaza Relatório

0

If you are looking for a solution to get the lat and lng then here is how you can get inside the function you are using

   lat = p.coords.latitude;
   lng = p.coords.longitude;

Then you can learn how to insert data in DOM something like this

document.getElementById('latvalue').innerHTML += lat;
document.getElementById('lngvalue').innerHTML += lng;
about 4 years ago · Juan Pablo Isaza Relatório
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