Javascript Google Maps v3通过jQuery$.ajax和json添加标记
我在使用jquery向GMAP添加地图标记时遇到问题。这是到目前为止我的代码 现在,我得到的错误是Javascript Google Maps v3通过jQuery$.ajax和json添加标记,javascript,google-maps,jquery,google-maps-api-3,Javascript,Google Maps,Jquery,Google Maps Api 3,我在使用jquery向GMAP添加地图标记时遇到问题。这是到目前为止我的代码 现在,我得到的错误是uncaughtreferenceerror:GLatLng未定义 映射加载良好,json数据正在正确获取和解析。。。据我所知……;) 添加地图插针/标记或您称之为em的w/e…。 EventsModel.prototype.fetchMapPoints = function() { $.ajax({ dataType: "json", url: '../.
uncaughtreferenceerror:GLatLng未定义
映射加载良好,json数据正在正确获取和解析。。。据我所知……;)
添加地图插针/标记或您称之为em的w/e…。
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);
});
}
以下是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
来自谷歌地图API的第2版,但您使用的是第3版,因此将其更改为Google.Maps.LatLng
至少应该能够解决这个问题。以下是使其工作的代码
EventsView.prototype.addMapPin = function(location)
{
var myLatlng = new google.maps.LatLng(location.lat,location.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
}
EventsView.prototype.addMapPin = function(location)
{
var myLatlng = new google.maps.LatLng(location.lat,location.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
}