0

我正在尝试将 json 文件中的纬度和经度解析到谷歌地图上,以及将其他几个数据解析到信息窗口中。但是我认为当我尝试运行文件时,我认为可能在某个地方搞砸了,我得到的只是一个空白屏幕。有人可以指出我做错了什么。任何建议将不胜感激。

我使用了谷歌创建的地震数据作为我的参考点。

>   window.eqfeed_callback = function(results) {
      var bounds=new google.maps.LatLngBounds();
      for (var i = 0; i < results.features.length; i++) {

        var accesspoint = results.features[i]; 
        var latitude = accesspoint.3.WifiLatitude;
        var longtitude = accesspoint.4.WifiLongtitude;      

        var latLng = new google.maps.LatLng(latitude &&longtitude); 
        bounds.extend(latLng);
        var content ="<div style='height:100px; width:300px; overflow:auto;'><table>";
    content += "<tr><th align='left'>id</th><td>"+accesspoint.id+"</td></tr>";
    content += "<tr><th align='left'>WifiMacAddress</th><td>"+accesspoint.4.WifiMacAddress+"</td></tr>";
    content += "<tr><th align='left'>WifiSSID</th><td>"+accesspoint.4.WifiSSID+"</td></tr>";
    content += "<tr><th align='left'>WifiFrequency</th><td>"+accesspoint.4.WifiFrequency+"</td></tr>";
    content += "<tr><th align='left'>SignalStrength</th><td>"+accesspoint.4.SignalStrength+"</td></tr>";
    content +="</table>";
    createMarker(latLng,earthquake.id,content);

我一直在尝试解析数据的 json 文件

   {"wifin":{"WifiMacAddress":["21-00-00-00-00-00"],"WifiSSID":"Edurom","WifiLatitude":[-27.501008],"WifiLongtitude":[153.011720],"WifiFrequency":"80","SignalStrength":"60"},

"wifin":{"WifiMacAddress":["21-00-00-00-00-00"],"WifiSSID":"Edurom","WifiLatitude":[-27.501541],"WifiLongtitude":[153.005755],"WifiFrequency":"80","SignalStrength":"60"},

"wifin":{"WifiMacAddress":["21-00-00-00-00-00"],"WifiSSID":"Edurom","WifiLatitude":[-27.499142],"WifiLongtitude":[153.008845],"WifiFrequency":"80","SignalStrength":"60"},

"wifin":{"WifiMacAddress":["21-00-00-00-00-00"],"WifiSSID":"Edurom","WifiLatitude":[-27.498000],"WifiLongtitude":[153.015153],"WifiFrequency":"80","SignalStrength":"60"},

"wifin":{"WifiMacAddress":["21-00-00-00-00-00"],"WifiSSID":"Edurom","WifiLatitude":[-27.495069],"WifiLongtitude":[153.011549],"WifiFrequency":"80","SignalStrength":"60"}

}
4

1 回答 1

0

google.maps.LatLng 对象将两个数字作为其参数。这是不正确的:

var latLng = new google.maps.LatLng(latitude &&longtitude); 

应该

var latLng = new google.maps.LatLng(latitude , longtitude); 

更安全的是:

var latLng = new google.maps.LatLng(parseFloat(latitude), parseFloat(longtitude));

由于来自 JSON,它们都是字符串。您甚至可以通过在使用它们构建 google.maps.LatLng 之前测试“isNaN”来验证它们是有效数字。

于 2013-08-27T13:18:42.187 回答