![](/img/trans.png)
[英]Cannot import com.google.android.gms.maps.model.LatLng in Android Studio
[英]cannot resolve symbol 'add' List<com.google.android.gms.maps.model.LatLng>
我正在尝试使用 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方法为折线创建列表。
首先创建一个这样的折线
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.
考虑到.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
对其进行了测试,当currentPoint
在距离内时返回true
当currentPoint
超出options
的坐标范围时返回false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.