Google Maps - Panning and Zooming into areas - markers not appearing when I zoom in or pan

天涯浪子 提交于 2019-12-02 07:20:37

I have a page that works exactly the same way that you have described yours. Here's how I get the bounds:

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();

I then send each value to the server. I previously checked for points within the bounds with a query like this:

WHERE (lat BETWEEN $sBound AND $nBound) AND (lng BETWEEN $wBound AND $eBound)

However, I recently discovered that this query fails when the bounds area includes the international date line. This doesn't look like the problem that you're having (it's probably happening in parsing the bounds), but it's definitely something you should consider. Here's how I fixed it:

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)";
}

If this is literally copied from the code:

$sql .= ' (a.`latitude` >= $lbound) AND (a.`latitude` <= $ubound)';

then the issue may simply be that you're using single quotes rather than double on the PHP literals. As such, the $lbound and $ubound interpolation doesn't happen, and you're using an invalid SQL query.

Try:

$sql .= " (a.`latitude` >= $lbound) AND (a.`latitude` <= $ubound)";

etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!