无法解析符号'添加'列表

问题描述 投票:0回答:2

我正在尝试使用PolyUtil.isLocationOnPath,它要求java.util.Listcom.google.android.gms.maps.model.LatLng而不是java.util.List com.google.type.LatLng。因此,当我尝试创建如下列表时:

 List<com.google.android.gms.maps.model.LatLng> path3 = new ArrayList<>();
 path3.add(new com.google.android.gms.maps.model.LatLng(-35.016, 143.321),
           new com.google.android.gms.maps.model.LatLng(-34.747, 145.592),
           new com.google.android.gms.maps.model.LatLng(-34.364, 147.891),
           new com.google.android.gms.maps.model.LatLng(-33.501, 150.217),
           new com.google.android.gms.maps.model.LatLng(-32.306, 149.248),
           new com.google.android.gms.maps.model.LatLng(-32.491, 147.309))

 public boolean checkLocationOnRoute(){
   return  onRoute = PolyUtil.isLocationOnPath(currentPoint, path, false, 100);
 }

这导致cannot resolve symbol 'add'错误。如何使用所需的List<com.google.android.gms.maps.model.LatLng>和isLocationOnPath方法为折线创建List。

android google-maps-android-api-2
2个回答
0
投票

首先创建这样的折线

PolylineOptions options = new PolylineOptions().geodesic(true);
options.add(new com.google.android.gms.maps.model.LatLng(-35.016, 143.321));
options.add(new com.google.android.gms.maps.model.LatLng(-34.747, 145.592));
// Add all remaining points
Polyline line = mgGoogleMap.addPolyline(options);

现在,您可以检查您的点是否位于折线中,如下所示:

PolyUtil.isLocationOnPath(currentPoint, line.getPoints(), true)
// The true here refers to geodesic true.

0
投票

考虑到.add(new com.google.android.gms.maps.model.LatLng(Lat, Lng));扔了一个cannot resolve symbol 'add',我将以下所有代码放在我的requestLocationUpdates方法中:

List<com.google.android.gms.maps.model.LatLng> options = new ArrayList<>();

                options.add(new com.google.android.gms.maps.model.LatLng(-35.016, 143.321));
                options.add(new com.google.android.gms.maps.model.LatLng(-34.747, 145.592));// Add all remaining points                    

                onRoute = PolyUtil._isLocationOnPath_(currentPoint, options, true, 490);

我还使用490m作为tolerance测试了它,当true在距离内时返回currentPoint,然后当false超出currentPoint坐标范围时options

© www.soinside.com 2019 - 2024. All rights reserved.