我在標記的服務器端實施一些基於邊界的聚類,以在我的谷歌地圖上顯示。我正在做的是,我有一個函數,每次映射移動或平移或縮放時都會調用該函數,該函數接受映射的邊界並進行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