javascript – Google Maps v3通过jQuery $.ajax和json添加标记

前端之家收集整理的这篇文章主要介绍了javascript – Google Maps v3通过jQuery $.ajax和json添加标记前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有问题是使用 jquery将地图标记添加到gmaps.到目前为止,这是我的代码.

现在,我得到的错误是Uncaught ReferenceError:未定义GLatLng

地图加载正常,正在获取和解析json数据…从我可以告诉…;)

添加地图引脚/标记或w / e你称之为em …

EventsModel.prototype.fetchMapPoints = function()
{
    $.ajax({
        dataType: "json",url: '../../events/map',success: eventsV.writeMapPoints
    });
}

EventsView.prototype.writeMapPoints = function(Locations)
{
    if (Locations.length>0) { 
      for (i=0; i<Locations.length; i++) { 
        var location = Locations[i]; 
        eventsV.addMapPin(location); 
      } 
      //zoomToBounds(); 
    }
}

EventsView.prototype.addMapPin = function(location)
{
    var point = new GLatLng(location.lat,location.lng); 
    var marker = new GMarker(point); 
    map.addOverlay(marker); 
    bounds.extend(marker.getPoint()); 
    $("<li />")
    .html(location.name) 
    .click(function(){ 
      showMessage(marker,location.name); 
    }) 
    .appendTo("#list"); 
    GEvent.addListener(marker,"click",function(){ 
    showMessage(this); 
    }); 

}

地图初始化

EventsModel.prototype.fetchGmapScript = function()
{
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=eventsV.initializeMap";
    document.body.appendChild(script);
}

EventsView.prototype.initializeMap = function()
{
    var myLatlng = new google.maps.LatLng(coords.lat,coords.long);
    var myOptions = {
    zoom: 13,center: myLatlng,mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("Map"),myOptions);
}

这是json数据的样子

[{"Event":"c16a5320fa475530d9583c34fd356ef5","lat":"37.8966942","lng":"-122.0599376","Image":"321752348.png","name":"Winning apple store","Description":""},{"Event":"b6d767d2f8ed5d21a44b0e5886680cb9","lat":"37.8995050","lng":"-122.0619770","Image":"","name":"Koreana Kitchen","Description":"Peter isn't invited!"}]

解决方法

就像错误说的那样,GLatLng没有定义. GLatLng来自Google Maps API的第2版,但您使用的是版本3,因此将其更改为google.maps.LatLng至少应该将其排除在外.

猜你在找的Ajax相关文章