我正在尝试将json文件中的纬度和经度解析到Google地图上,以及将其他几个数据解析到信息窗口中。但是我觉得可能已经搞砸了,因为当我试图运行文件时,我得到的只是一个空白屏幕。有人可以指出我做错了什么。任何建议都将不胜感激。
我已经利用谷歌创建的地震数据作为我的参考点。
> 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"}
}
答案 0 :(得分:0)
a google.maps.LatLng object以两个数字作为参数。这是不正确的:
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”来验证它们是有效数字。