¿Cómo puedo obtener las coordenadas y mostrarlas como un enlace de Google Maps en la salida? No pude resolverlo y cualquier consejo sería de mucha ayuda. Gracias. El contenido de datos API está vinculado como una imagen a continuación. [`
function searchCity(city) { //var r=JSON.parse(xhr.responseText); document.getElementById("searchvalues").innerHTML = "Search by City" + "<br>"; //structure table var output = "<tr><th> Location </th><th> City </th><th> Phone </th><th> Vaccine Type </th><th> Map Link</th></tr>"; var searchid; var map = obj.point{coordinates:[]};; for (var i = 0; i < r.length; i++) { var obj = r[i]; searchid = obj.city.toUpperCase(); if (searchid.startsWith(city.toUpperCase())) { output += "<tr><td>"; output += obj.location; output += "</td><td>"; output += obj.city; output += "</td><td>"; output += obj.phone; output += "</td><td>"; output += obj.vaccinetype; output += "</td><td>"; output += <a href='https:www.google.com/maps/search/?api=1&query=' + map + ' target=_blank'> Click here to see map </a>; output += "</td></tr>"; } } document.getElementById("searchresults").innerHTML = output; }
`] 1
obj.point.coordinates
probarlo
es una matriz
var map = obj.point{coordinates:[]};;
siempre no cambie, puede establecer coordenadas para vincular igual que:
let coordinate = obj.point.coordinates.reverse().toString(); output += <a href='https:www.google.com/maps/search/?api=1&query=' + coordinate + ' target=_blank'> Click here to see map </a>;
Lo mismo que:
function searchCity(city) { //var r=JSON.parse(xhr.responseText); document.getElementById("searchvalues").innerHTML = "Search by City" + "<br>"; //structure table var output = "<tr><th> Location </th><th> City </th><th> Phone </th><th> Vaccine Type </th><th> Map Link</th></tr>"; var searchid; for (var i = 0; i < r.length; i++) { var obj = r[i]; searchid = obj.city.toUpperCase(); if (searchid.startsWith(city.toUpperCase())) { output += "<tr><td>"; output += obj.location; output += "</td><td>"; output += obj.city; output += "</td><td>"; output += obj.phone; output += "</td><td>"; output += obj.vaccinetype; output += "</td><td>"; let coordinate = obj.point.coordinates.reverse().toString(); output += <a href='https:www.google.com/maps/search/?api=1&query=' + coordinate + ' target=_blank'> Click here to see map </a>; output += "</td></tr>"; } } document.getElementById("searchresults").innerHTML = output; }