ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

PHP-Google Maps-平移和放大区域-放大或平移时标记不出现

2019-10-13 01:31:37  阅读:150  来源: 互联网

标签:javascript php google-maps coordinates


我正在标记的服务器端实现一些基于边界的聚类,以显示在我的Google地图上.我正在做的是,我有一个函数,它在每次地图移动,平移或缩放时都会被调用,该函数获取地图的边界并进行ajax调用,而服务器端脚本又运行一个简单的sql查询来检索标记并将它们聚类.到目前为止,集群部分运行良好,但是有时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)";
}

标签:javascript,php,google-maps,coordinates
来源: https://codeday.me/bug/20191013/1904423.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有