1

I have coordinates stored in my database, and I want to fetch those coordinates to display on Google Maps, where the user will click on the link which says like "view on map" in the column table. However, the link will redirect to that map based on stored coordinates from the database, and I don't know how to fetch those coordinates from the database with JavaScript.

var map;
var myLatLng;

function initMap() {
  
  var loc = { lat: -74.17972, lng:34.56445312 };
 
  
  var map = new google.maps.Map(document.getElementById("map"), {
    zoom: 8,
    center: loc,
  });
  
  var marker = new google.maps.Marker({
    position: loc,
    map: map,
    draggable: true
  });
}

1 Answer 1

1

I believe the way to make client js talks to you db , will be through an API Call by Ajax.

You can create an Api route and controller function to handle query the coords from the DB and test it out

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.