谷歌地图 - 平移和缩放成不同的区域 - 标记没有出现,当我在或平移缩放
-
11-09-2019 - |
题
我执行上的标记的服务器端的一些边界基于聚类的显示在我的谷歌地图。我在做什么是我有一个被称为每次地图是移动或平移或缩放功能,这需要绑定的地图,并使得这反过来服务器端脚本运行一个简单的SQL查询来检索一个Ajax调用标记和集群他们。到目前为止,德集群部分工作很好但是有时候的getBounds似乎并没有被发送正确的边界,我觉得。
就像我可以平移地图上曾经有过的标记,现在突然没有标记的侧面和地区位和地图是空白。我检查了SQL查询,从查询本身就说明比预期悍然不同的界限。
看看下面的区域:
第一个显示的所有标记。
在一个以下然而刚刚移动了位到顶部和左侧,但一半的区域是一样的,在先前的图象但是没有标记的。我已隔离问题以与地图的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功能,但需要尽快将其修复。任何想法请:(
解决方案
我的作品正是你所描述你的相同方式的页面。以下是我得到的边界:
var bounds = map.getBounds();
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var s = sw.lat();
var w = sw.lng();
var n = ne.lat();
var e = ne.lng();
我然后发送每一个值到服务器。我先前检查点与这样的查询的范围内:
WHERE (lat BETWEEN $sBound AND $nBound) AND (lng BETWEEN $wBound AND $eBound)
不过,我最近发现,当边界区域包括国际日期变更线查询失败。这看起来不像是和自己(它在解析的范围可能发生)的问题,但它绝对是你应该考虑的问题。以下是我固定它:
if ($wBound > $eBound) { // if bounds includes the intl. date line
$sql .= "WHERE (lat BETWEEN $sBound AND $nBound) AND ((lng BETWEEN -180 AND $eBound) OR (lng BETWEEN $w AND 180))";
} else {
$sql .= "WHERE (lat BETWEEN $sBound AND $nBound) AND (lng BETWEEN $wBound AND $eBound)";
}
其他提示
如果这是从字面上代码复制:
$sql .= ' (a.`latitude` >= $lbound) AND (a.`latitude` <= $ubound)';
那么问题可能仅仅是你使用单引号,而不是双对PHP的文字。因此,$ LBOUND和UBOUND $插不发生,并且您使用的是无效的SQL查询。
尝试:
$sql .= " (a.`latitude` >= $lbound) AND (a.`latitude` <= $ubound)";
等
不隶属于 StackOverflow