Head First C与JSON文件关联的Google Map

时间:2014-03-03 18:03:33

标签: javascript json google-maps gps

这个问题来自Griffiths的Head First C一书。从第p页开始110该书指导如何开发一个JSON文件,该文件将由网站http://oreillyhfc.appspot.com/map.html上的地图应用程序读取。从包含CSV格式的纬度和经度值的文件开始,开发C程序将其转换为JSON文件。到目前为止,由于我缺乏知识,我怀疑生成的输出文件是否符合JSON文件的标准。

问题在上一步之后开始。首先,当我尝试整个网页(从Chrome,Firefox在Ubuntu 12.04.3 32位和Windows 7 64位上)时,map.html文件的本地副本是无用的。双击文件时,将显示一个白色空白页面,没有要查看的地图。但是,当使用唯一的html文件选项保存时,将显示地图,但程序不会读取同一目录中的JSON文件以显示相应的红色标记。这可能是背后的原因,我该如何纠正这种情况?这些天它一直困扰着我。

提前致谢

相应的文件是

“output.json”

data=[
{latitude: 42.363400, longitude: -71.098465, info: 'Speed = 21'},
{latitude: 42.363327, longitude: -71.097588, info: 'Speed = 23'},
{latitude: 42.363255, longitude: -71.096710, info: 'Speed = 17'},
{latitude: 42.363182, longitude: -71.095833, info: 'Speed = 22'},
{latitude: 42.363110, longitude: -71.094955, info: 'Speed = 14'},
{latitude: 42.363037, longitude: -71.094078, info: 'Speed = 16'},
{latitude: 42.362965, longitude: -71.093201, info: 'Speed = 18'},
{latitude: 42.362892, longitude: -71.092323, info: 'Speed = 22'},
{latitude: 42.362820, longitude: -71.091446, info: 'Speed = 17'},
{latitude: 42.362747, longitude: -71.090569, info: 'Speed = 23'},
{latitude: 42.362675, longitude: -71.089691, info: 'Speed = 14'},
{latitude: 42.362602, longitude: -71.088814, info: 'Speed = 19'},
{latitude: 42.362530, longitude: -71.087936, info: 'Speed = 16'},
{latitude: 42.362457, longitude: -71.087059, info: 'Speed = 16'},
{latitude: 42.362385, longitude: -71.086182, info: 'Speed = 21'}
]

“gpsdata.csv”

42.363400,-71.098465,Speed = 21
42.363327,-71.097588,Speed = 23
42.363255,-71.096710,Speed = 17
42.363182,-71.095833,Speed = 22
42.363110,-71.094955,Speed = 14
42.363037,-71.094078,Speed = 16
42.362965,-71.093201,Speed = 18
42.362892,-71.092323,Speed = 22
42.362820,-71.091446,Speed = 17
42.362747,-71.090569,Speed = 23
42.362675,-71.089691,Speed = 14
42.362602,-71.088814,Speed = 19
42.362530,-71.087936,Speed = 16
42.362457,-71.087059,Speed = 16
42.362385,-71.086182,Speed = 21

P.S。我完全按照书中的说法做了,我对JS非常不熟悉。

3 个答案:

答案 0 :(得分:1)

打开O'Reilly地图网站.. Den点击设置 - >工具 - >查看源代码.. 复制粘贴记事本中的代码保存为map.HTML在同一文件夹中存储所有其他文件.. 双击map.HTML,它将找到output.json文件的信息

答案 1 :(得分:1)

操作系统:Ubuntu 14.04 浏览器:Mozilla 我和你有同样的问题,但现在,我找到了确切的解决方案。所以我做了什么:

1-我安装了Apache Server。 (实际上我已经在ubuntu上了它)

2-打开http://oreillyhfc.appspot.com/map.html和ctrl + s并将其保存为“所有文件”(非“网页,完全”)到我的geo2json项目文件夹。

3-我将geo2json项目文件夹移动到localhost。 (就像那样:/ var / www / html / geo2json /)

---不要忘记成为root用户能够移动文件=> sudo -i

---移动命令=> mv geo2jsonFolderLocation / var / www / html

4-然后打开我的浏览器(Mozilla)并链接localhost / geo2json / map.html

它有效!

答案 2 :(得分:1)

最好的办法是安装XAMPP并在您的计算机上运行Apache服务器。

请注意通过C文件输出的数据格式,因为我发现许多其他人都错过了撇号,而map.html无法解析它。

在放置文件map.htmloutput.json之后(请注意硬编码的名称),使用网址http://localhost/gpsdata/map.html运行它。并且不要忘记放大,因为它看起来像默认条件下的一个点。

你必须将其缩放六次并voilà:你会看到骑车人跟踪的痕迹。