繁体   English   中英

如何从 object 中的数组获取经纬度数据并将其显示为 output 上的 google map 链接

[英]How to get longitude and latitude data from an array inside object and display them as google map link on output

如何获取坐标并将其显示为 output 上的 Google 地图链接? 我想不通,任何建议都会很有帮助。 谢谢你。 API数据内容链接如下图。 [`

 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.vacc.netype; 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尝试一下

它是一个数组

var map = obj.point{coordinates:[]};; 始终不要更改,您可以将坐标设置为与以下链接相同:

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>;

它与:

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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM