Reputation: 11
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
});
}
Upvotes: 1
Views: 593
Reputation: 31
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
Upvotes: 1