无法将JSON数据传递到嵌入式地图

时间:2014-09-11 04:52:05

标签: javascript json google-maps google-maps-api-3 getjson

我正在尝试构建一个将在地图上显示多个点的页面,每个点代表一个带有标题,位置,日期,链接和描述的预定事件。对于地图本身,我使用maplace插件(http://maplacejs.com),并将事件存储在.json文件中。目前,我在日志中没有出现任何错误,并且地图会在页面加载时显示,但这些点不会出现。这是相关代码:

data.json

{ "allEvents": [

  {
  "eventName" : "Event #1",
  "eventDate" : "May 27, 2014",
  "lat": "52.963619",
  "long": "-125.619140",
  "link": "http://www.google.com"
  "description" : "short description"},
]}

在我的标题脚本

 var eventLocations = [];
 $.getJSON('data.json', function(events) {
        for (var i in data.allEvents) {
            var name = data.allEvents[i].eventName;
            var date = data.allEvents[i].eventDate;
            var latitude = data.allEvents[i].lat;
            var longitude = data.allEvents[i].long;
            var link = data.allEvents[i].link;
            var desc = data.allEvents[i].description;

            var loc = "{ lat: " + latitude + "," +
                        "lon: " + longitude + "," +
                        "icon: images/icon3.png," +
                        "title: " + name + "," +
                        "html: <div class='infoWindow'>" +
                        "<h3>" + name + "</h3>" +
                        "<h4>" + date + "</h4>" +
                        "<a href='http://" + link + "' target='_blank'>view website</a>" +
                        "<p>" + desc + "</p>" +
                        "</div> },";

            eventLocations.push(loc);                

        };
    });

$(function() {
  var maplace = new Maplace({

    //I have lots of other parameters here (controls, stylers, options, etc)

    locations: [ eventLocations ]
  }); 

  maplace.Load();

还值得一提的是,如果我在Maplace中写出一个位置(即代替&#39; eventLocations&#39;变量,则该引脚显示正常。

提前致谢!

0 个答案:

没有答案