har*_*nan 13 android google-maps-api-2 google-polyline
我想touchListener在使用Google Maps V2 Android API显示的折线上实现一个.
缩放级别:
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(lat_Lng, 5);
我尝试了以下折线触摸代码:
boolean onpoly = false;
for (Polyline polyline : mPolylines) {
for (LatLng polyCoords : polyline.getPoints()) {
float[] results = new float[1];
Location.distanceBetween(points.latitude, points.longitude, polyCoords.latitude, polyCoords.longitude, results);
if (results[0] < 100 ) {
onpoly = true;
Marker mark = map.addMarker(new MarkerOptions().position(points).title("AddEvent")
.snippet("" + addressaddexpense).icon(BitmapDescriptorFactory.fromResource(R.drawable.addicon)));
UtilsClass.dropPinEffect(mark);
}// end if..
} // end for loop
}// end for loop
if (onpoly == true) {
Toast.makeText(getActivity(), "Poly line detected", Toast.LENGTH_SHORT).show();
}// end if
Run Code Online (Sandbox Code Playgroud)
它工作但不完美.它不会检测到触摸事件,除非我放大,有时迫使我在缩放之前点击地图超过5次以实现检测.
然后我将上述if条件从更改为if (results[0] < 100 ),if (results[0] < 150 * (22 - map.getCameraPosition().zoom))并且功能得到了改进,但它仍然不能一直工作.
注意:我想在任何缩放级别检测折线触摸.
在我的评论中的问题得到解答之前,我想我会尝试通过建议使用第三方库来使它们变得多余;android-maps-utils
要执行我认为您可能会尝试执行的操作,只需集成库并使用以下行:
PolyUtil.isLocationOnPath(point, polyline.getPoints(), isGeodesic, tolerance);
欲了解更多信息,您还可以查看此线程似乎适用的
祝你好运。
| 归档时间: |
|
| 查看次数: |
1768 次 |
| 最近记录: |