且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google地图-平移和放大区域-放大或平移时不会出现标记

更新时间:2023-08-30 13:59:10

我有一个页面的工作方式与您描述自己的方式完全相同。这就是我的方法边界:

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