解析数据到谷歌地图上 [英] Parsing data onto google map

查看:129
本文介绍了解析数据到谷歌地图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从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&& longitude);
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\" ,SignalSt rength:60}

}


解决方案 div>

google.maps.LatLng对象需要两个数字作为其论据。这是不正确的:

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

应该是

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

并且更安全:

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

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

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

}

解决方案

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.

这篇关于解析数据到谷歌地图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆