Android 多段线出现在地图上它们不应该出现的位置';T

Android 多段线出现在地图上它们不应该出现的位置';T,android,google-maps,google-maps-android-api-2,Android,Google Maps,Google Maps Android Api 2,我有一个大约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

我有一个大约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());
if(c.moveToFirst())
做{
lat=c.getString(0);
lng=c.getString(1);
ac=c.getString(2);
alt=c.getString(3);
如果(l1!=null){
l2=新位置(“地图”);
l2.setLatitude(Double.parseDouble(lat));
l2.设置经度(Double.parseDouble(lng));
l2.设置高度(双精度、双精度(alt));
l2.设置精度(Float.parseFloat(ac));
如果(l1)距离(l2)<1000
&&l2.getAccurance()<51){
选择添加(新板条)(双板条)(板条),
双倍,双倍(lng);;
列表。添加(l2);
l1=l2;
}
}否则{
l1=新位置(“地图”);
l1.设置纬度(双精度、双精度(纬度));
l1.设置经度(双精度。解析双精度(lng));
l1.设定精度(浮点。解析浮点(ac));
l1.设置高度(双精度、双精度(alt));
如果(l1.GetAccurance()>50)
l1=零;
}
}而(c.moveToNext());
这样就排除了这些随机线假设其正常工作的可能性

当它正常工作时,它应该是这样的:

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

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

我正在添加这样的行:

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);
Location[]locations=Arrays.copyOfRange(mLocations,a,b);
if(mStartLine!=null)
mStartLine.remove();
如果(mmidLine!=null)
mmidLine.remove();
if(mEndLine!=null)
mEndLine.remove();
如果(mMarker!=null){
mMarker.remove();
mMarker=null;
}
PolylineOptions so=新的PolylineOptions();
PolylineOptions mo=新的PolylineOptions();
PolylineOptions eo=新的PolylineOptions();
所以。颜色(颜色。绿色);
eo.颜色(颜色.绿色);
颜色(颜色为黑色);
如果(位置。长度<2){
如果(locations.length==0)
返回;
//只加一个点。
MarkerOptions m=新的MarkerOptions();
m、 位置(新车床位置[0]。getLatitude(),位置[0]
.getLongitude());
mMarker=mMap.addMarker(m);
返回;
}
添加(新LatLng(位置[0].getLatitude(),位置[0].getLatitude());
添加(新LatLng(位置[1].getLatitude(),位置[1].getLatitude());
mStartLine=mMap.addPolyline(so);
对于(int i=1;i<(locations.length-1);i++){
mo.add(新LatLng(位置[i].getLatitude(),位置[i].getLatitude());
}
mmidLine=mMap.addPolyline(mo);
添加(新LatLng(位置[locations.length-2].getLatitude(),位置[locations.length-2].getLatitude());
添加(新LatLng(位置[locations.length-1].getLatitude(),位置[locations.length-1].GetLength());
mEndLine=mMap.addPolyline(eo);

底部的栏是一个选择器,仅显示位置范围(因为当显示7000个位置时,它会变得非常疯狂,并且会出现
StackOverflowerError

似乎有一个bug为它打开:

编辑

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

更新

这个bug是在Google问题跟踪程序中处理的

它在Google Play Services-9.2.56中被修复


以下是一种解决我们这个问题的方法。不一定是理想的解决方案,但它是有效的。在某些缩放级别,您可能会看到多段线延伸到超出其应位于的位置(如上图所示)。如果继续更改缩放级别,则扩展将消失,然后重新出现。每当两个坐标完全相同时,这种情况就会发生在我们身上。e、 g

假设你有3个坐标A,B,C。总线从A开始到B,然后总线转向C。如果A和C是完全相同的坐标,你会看到这个多段线延伸问题


经过几次接近后,我们决定将C点的纬度偏移.00001。这解决了我们所有的问题。

如果我找到答案,我会把它贴在这里。现在我只有这些了。这个问题有什么解决办法吗?