我在标记的服务器端实施一些基于边界的聚类,以在我的谷歌地图上显示。我正在做的是,我有一个函数,每次映射移动或平移或缩放时都会调用该函数,该函数接受映射的边界并进行ajax调用,然后服务器端脚本运行简单的SQL查询来检索标记并将它们聚类。到目前为止,集群部分工作得很好,但有时getBounds似乎并没有发送我感觉到的正确界限。谷歌地图 - 平移和缩放区域 - 当我放大或缩小时,标记不会出现 - 帮助!
就像我可以在地图上稍微拖动一边,以前有标记的地区突然没有标记,地图也是空白的。我检查了SQL查询,并从查询本身显示了一个蛮横不同的界限比预期。
在以下地区看一看: Orginal WitH Markers http://i31.tinypic.com/xds4t0.jpg No markers http://i31.tinypic.com/2r22ez4.jpg
第一个显示所有标记。
然而,后面的一个刚刚移动了一些顶部和左侧,但一半的区域是与前一张图片相同,但根本没有标记。我已经将问题隔离到了地图的getBounds函数中。
这是我的JavaScript代码,得到边界和进行呼叫:
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var data = {ne:northEast.toUrlValue(), sw:southWest.toUrlValue(), zoom:map.getZoom()};
//something getting messed up in the code above this point
$.ajax({
type: "POST",
url: 'maps/get-markers',
data: {object:$.toJSON(data)},
dataType: 'json',
success: function(response) {
//code to add markers
}
});
在我的服务器端代码,这是用来获取基于坐标的项目的PHP:
$data = Zend_Json::decode(stripslashes($this->_request->getParam('object')));
//retrieve the variables from the GET vars
list($nelat, $nelng) = explode(',', $data['ne']);
list($swlat, $swlng) = explode(',',$data['sw']);
//clean the data
$nelng = (float)$nelng;
$swlng = (float)$swlng;
$nelat = (float)$nelat;
$swlat = (float)$swlat;
$ubound = $swlng > $nelng ? $swlng : $nelng;
$lbound = $swlng > $nelng ? $nelng : $swlng;
$sql = 'SELECT `a`.* FROM `locations` AS `a` WHERE (a.`longitude` > $lbound) AND (a.`longitude` < $ubound) AND';
$ubound = $swlat > $nelat ? $swlat : $nelat;
$lbound = $swlat > $nelat ? $nelat : $swlat;
$sql .= ' (a.`latitude` >= $lbound) AND (a.`latitude` <= $ubound)';
我怀疑它的JavaScript中的getbounds函数,但需要尽快解决它。任何想法请:(
得到它固定的 - 我所有的20个000标记已经搞砸了位置:)感谢所有的答复! – Ali 2010-02-20 12:26:02