我正在从数据库中获取标记详细信息。 代码是
app.entries[id].data = {'id': id, 'map': entry[1].innerHTML,'type_id':
entry[2].innerHTML,'name': entry[3].innerHTML,'descript': entry[4].innerHTML, 'parish':
entry[5].innerHTML,'zip': entry[6].innerHTML, 'url': entry[7].innerHTML, 'lng':
entry[8].innerHTML,'lat':entry[9].innerHTML,'tags':entry[10].innerHTML,'img':
entry[11].innerHTML,'imgs':entry[12].innerHTML};
app.entries[id].data.imgHTML = (app.entries[id].data.img == "") ? "" :
fill_template(app.entries[id].data,app.infoWindowImageHTML);
var str = fill_template(app.entries[id].data,app.searchRowHTML);
html.push(str);
if (app.entries[id].data.lat != 0 || app.entries[id].data.lng != 0) {
var point = new GLatLng(app.entries[id].data.lat,app.entries[id].data.lng);
var m = new GMarker(point,{draggable: true});
GEvent.addListener(m, "dragstart", function() {
// map.closeInfoWindow();
var latlngold = m.getLatLng();
});
GEvent.addListener(m, "dragend", function() {
var m = new GMarker(point,{draggable:true});
m.entry_id = id;
var p=m.entry_id;
var latlngnew = m.getLatLng();
alert(latlngnew);
//m.setLatLng(new GLatLng(latlng));
editentry1(latlngnew,p);
});
}
dragend
和dragstart
函数始终采用最后一个标记的详细信息,而不是拖动标记的详细信息。
function editentry1(latlngnew,p){
var newlat=latlngnew.lat();
var newlng=latlngnew.lng();
var d = new Date();
var dv = d.valueOf();
var url = "<?php echo $g['appPath']; ?>admin/editPoint.php?d="+dv+"&
newlat = “+ newlat +” newlng = “+ newlng +” &安培; P =“+ P;
var s = $('mapStatus');
s.innerHTML =“EDiting Point ......”;
s.show();
new Ajax.Request(url, {
method: 'get',
onSuccess: editEntryReturn,
onFailure: requestFailed
});
}
editPoint.php
需要( “createThumb.php”);
$ newlng = $ _GET ['newlng'];
$newlat = $_GET['newlat'];
$p=$_GET['p'];
$ q =“UPDATE条目SET lat ='$ newlat',lng ='$ newlng'WHERE id ='$ p';”;
$r = updateBatch($q);
} ?&GT; 但标记的位置不会改变
答案 0 :(得分:0)
将标记创建代码包装在函数中。这将创建一个closure,其中拖动回调可以找到相应的标记对象:
function createMarker (point)
{
var m = new GMarker(point,{draggable: true});
GEvent.addListener(m, "dragstart", function() {
var latlngold = m.getLatLng();
});
GEvent.addListener(m, "dragend", function() {
var latlngnew = m.getLatLng();
editentry1(latlngold,latlngnew);
});
return m;
}
在得到要点之后从if语句中调用:
if (app.entries[id].data.lat != 0 || app.entries[id].data.lng != 0)
{
var point = new GLatLng(app.entries[id].data.lat,app.entries[id].data.lng);
map.addOverlay(createMarker (point));
}