Parsing data onto google map

江枫思渺然 提交于 2020-01-06 15:00:13

问题


I am trying to parse the latitude and longitude from a json file onto Google map, as well as several other data into the information window. However i think might have screw up somewhere as when i tried to run the file, all i got was a blank screen. Can someone point out what i have done wrong. Any suggestion would be appreciated.

I have made use of the earthquake data created by google as my reference point.

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

the json file i have been trying to parse data out

   {"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"}

}

回答1:


a google.maps.LatLng object takes two numbers as its arguments. This is not correct:

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

should be

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

and safer to be:

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

as coming from JSON, they are both strings. You could even verify they are valid numbers, by testing "isNaN" before using them to construct the google.maps.LatLng.



来源:https://stackoverflow.com/questions/18464174/parsing-data-onto-google-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!