多段线出现在地图上不该出现的地方

2023-12-01

我有大约 7000 个位置的数组,每个位置都是使用 Android 上的位置管理器记录的,在加载这些位置时,我使用以下方法过滤掉距前一个位置超过 1 公里或精度高于 50 的任何位置:

if (c.moveToFirst())
do {
    lat = c.getString(0);
    lng = c.getString(1);
    ac = c.getString(2);
    alt = c.getString(3);
    if (l1 != null) {
        l2 = new Location("MAP");
        l2.setLatitude(Double.parseDouble(lat));
        l2.setLongitude(Double.parseDouble(lng));
        l2.setAltitude(Double.parseDouble(alt));
        l2.setAccuracy(Float.parseFloat(ac));
        if (l1.distanceTo(l2) < 1000
                && l2.getAccuracy() < 51) {
            opts.add(new LatLng(Double.parseDouble(lat),
                    Double.parseDouble(lng)));
            list.add(l2);
            l1 = l2;
        }
    } else {
        l1 = new Location("MAP");
        l1.setLatitude(Double.parseDouble(lat));
        l1.setLongitude(Double.parseDouble(lng));
        l1.setAccuracy(Float.parseFloat(ac));
        l1.setAltitude(Double.parseDouble(alt));
        if (l1.getAccuracy() > 50)
            l1 = null;
    }

} while (c.moveToNext());

因此,假设这些随机线正常工作,就消除了这些随机线的可能性。

当它正常工作时,它应该像这样出现:

enter image description here

然而,当我放大一点或四处移动时,有时我会得到这些随机线:

enter image description here enter image description here enter image description here enter image description here

我添加这样的行:

Location[] locations = Arrays.copyOfRange(mLocations, a, b);

if (mStartLine != null)
    mStartLine.remove();
if (mMiddleLine != null)
    mMiddleLine.remove();
if (mEndLine != null)
    mEndLine.remove();
if (mMarker != null) {
    mMarker.remove();
    mMarker = null;
}
PolylineOptions so = new PolylineOptions();
PolylineOptions mo = new PolylineOptions();
PolylineOptions eo = new PolylineOptions();

so.color(Color.GREEN);
eo.color(Color.GREEN);
mo.color(Color.BLACK);

if (locations.length < 2) {
    if (locations.length == 0)
        return;
    // Add just a dot instead.
    MarkerOptions m = new MarkerOptions();
    m.position(new LatLng(locations[0].getLatitude(), locations[0]
            .getLongitude()));
    mMarker = mMap.addMarker(m);
    return;
}
so.add(new LatLng(locations[0].getLatitude(), locations[0].getLongitude()));
so.add(new LatLng(locations[1].getLatitude(), locations[1].getLongitude()));
mStartLine = mMap.addPolyline(so);
for(int i = 1; i < (locations.length - 1); i++){
    mo.add(new LatLng(locations[i].getLatitude(), locations[i].getLongitude()));
}
mMiddleLine = mMap.addPolyline(mo);
eo.add(new LatLng(locations[locations.length - 2].getLatitude(), locations[locations.length - 2].getLongitude()));
eo.add(new LatLng(locations[locations.length - 1].getLatitude(), locations[locations.length - 1].getLongitude()));
mEndLine = mMap.addPolyline(eo);

底部的栏是一个选择器,仅显示该范围的位置(因为当您显示大约 7000 个位置时,它会变得非常疯狂,您会得到StackOverflowError's)


似乎有一个错误:https://code.google.com/p/gmaps-api-issues/issues/detail?id=5313

EDIT

如果过滤彼此距离小于 1 米的顶点,该错误就会得到解决。今晚晚些时候我将编写一些代码来解决这个问题并将其放在这里。

UPDATE

此错误已在 Google 问题跟踪器中处理

https://issuetracker.google.com/issues/35821816

它已在 Google Play 服务中修复 - 9.2.56

https://developers.google.com/maps/documentation/android-api/releases#june_27_2016

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

多段线出现在地图上不该出现的地方 的相关文章

随机推荐