通过舍入坐标矩形来缓存叠加层 - 如何?

时间:2013-02-05 09:23:08

标签: android overlay android-mapview coordinate-systems

我有一个包含我要缓存的叠加层的地图 - 用户在地图上访问的每个地方(这是一个矩形区域) - 我检查是否有一个位于此矩形中的叠加层缓存。

为了改善缓存(所以如果用户以前在同一个矩形上,除了现在他距离前一个矩形几米) - 我想“圆”坐标。

这样,每次用户都在矩形中 - 我检查这个矩形是否与之前缓存的矩形类似,如果是,我带来缓存的结果。

此外,如果用户缩小并且他的矩形包含在更大的(先前缓存的)矩形中 - 那么我也可以使用缓存的矩形。

有什么建议吗?

3 个答案:

答案 0 :(得分:1)

如果您只是在查看如何对坐标进行分组,请确定x和y坐标或纬度和经度之间的最大差异。然后有两种方法可以对它们进行分组。第一个更容易,但如果你有很多分数,它会很慢。

假设我们有一个名为cachedPoints的数据结构,称为maxdistance的相关点之间的最大距离以及我们试图检查它是否接近另一个被称为点的新点。

for each cachedPoint in cachedPoints
{
    if (point.x - cachedPoint.x < maxdistance)
    {
        if (point.y - cachedPoint.y < maxdistance)
        {
              cachedPoint.incrementvisits();  
        }
    }
}

另一种方法是使用按x或纬度排序的数据结构,然后搜索是否存在x或纬度在maxdistance点内的缓存点,然后检查y或longtitude。它会更快一点,但它需要某种哈希来实现,并增加了一些你可能不需要的复杂性。

希望这就是你所要求的。

答案 1 :(得分:1)

如果您设置了如下数据结构:

var a = { 'scales' : [50, 100, 200, 400, 1000],
   'cachedRects': [{'location': 'rect-large-1234-5678.png', x: 1234, y: 5678, scale: 3}
                   {'location': 'rect-small-1240-5685.png', x: 1240, y: 5685, scale: 1} ]
}

您可以使用模数函数来执行此操作:

var currentx = GetCurrentX();
var currenty = GetCurrentY();

var currentScale = GetCurrentScale();

var rectFound = false;

foreach(rect in a.cachedRects) {
    if (rect.scale === currentScale 
        && currentx % a.scales[currentScale] === rect.x
        && currenty % a.scales[currentScale] === rect.y) {
            rectFound = true;
            useOverlay(rect);
            break;
    }

}

if(!rectFound) {
    //could loop again for a larger rectangle of a lower scale.
}

以上可能会或可能不会证明是有效的JS - 我没有尝试过运行它。无论如何,我希望你能得到主旨。

答案 2 :(得分:0)

嘿,您可以在Android地图v2中添加标记。

这里我给出了添加标记的代码

    MarkerOptions mOpt = new MarkerOptions();
    mOpt.position(new LatLng(userHstry.getMyLatlng().latitude, userHstry.getMyLatlng().longitude)); // map.clear();
                mOpt.title("Address : " + userHstry.getAddress()).snippet("Date : " + userHstry.getDate() + " , Time : " + userHstry.getTime());
                map.addMarker(mOpt);