Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!