Reputation: 63
Hi Guys i want make a link and this link include latitude and longitude in javascript function can you help me about this.
My javascipt code:
function jsFilter(item) {
document.getElementById("myDiv").innerHTML = "";
item.Agency.forEach(agency=> {
$("#myDiv").append(
"<div style='border-style:ridge;'>Agency Name : <strong>" + agency.name+ "</strong><br>" +
"Agency Adress : <strong>" + agency.ADRESS_TEXT + "</strong><br>" +
"Agency EMail: <strong>" + agency.EMAIL+ "</strong></div>",
"https://maps.google.com/maps?q=" + agency.lat+ ',' + agency.lon // i wanna add here.
);
});
}
Upvotes: 1
Views: 461
Reputation: 778
Because the most of your code looks good, i guees you only needed the correct maps link and how the values are applyed to it?
Then thats what you need:
function jsFilter(item) {
document.getElementById("myDiv").innerHTML = "";
item.Agency.forEach(agency=> {
$("#myDiv").append(
"<div style='border-style:ridge;'>Agency Name : <strong>" + agency.name+ "</strong><br>" +
"Agency Adress : <strong>" + agency.ADRESS_TEXT + "</strong><br>" +
"Agency EMail: <strong>" + agency.EMAIL+ "</strong></div>" +
"<a href=\"https://maps.google.com/maps/@" + agency.lat + "," + agency.lon + "\">Google Maps Link</a>"
);
});
}
// EDIT Added the Link as HTML link.
As of the discussion in the comments, you needed a syntax for a HTML Link. Solution:
// replace this line:
"https://maps.google.com/maps?q=" + agency.lat+ ',' + agency.lon"
// with:
"<a href=\"https://maps.google.com/maps?q=" + agency.lat+ "," + agency.lon+ "\">google link</div>"
This will give you an working Google Maps link.
Upvotes: 1