我如何在android地图中显示接近路径路径的标记? [英] How can i show markers close to a route path in android maps?

查看:261
本文介绍了我如何在android地图中显示接近路径路径的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个地图活动的应用程序。



我在这个SO问题中发现了如何绘制2个点之间的路径:
答案:使用Google Maps Android API v2绘制两点之间的路径



如何只显示我的标记在半径范围内接近此路径的示例,例如500m?

PolyUtil.isLocationOnPath 方法。 Google Maps Android API实用程序库


计算给定点是否位于指定的公差范围内(以米为单位)或位于折线附近。如果测地线为真,则多段线由大圆段组成,否则由多段圆段组成。折线不关闭 - 不包括第一点和最后一点之间的闭合段。

public static boolean isLocationOnPath(LatLng point ,List< LatLng> polyline,布尔测地线,双公差)


您需要迭代标记并使其可见或不可见,具体取决于 PolyUtil.isLocationOnPath 的返回值与您所需的容差(在您的示例中为500):
$ b (标记标记:标记){
if(PolyUtil.isLocationOnPath(marker.getPosition(),yourRoutePath,false,500)){
$ b

  marker.setVisible(真); 
} else {
marker.setVisible(false);
}
}


I have an application with a map Activity. I also have put some markers on it.

I have found in this SO question how to draw a path between 2 points: Answer : Draw path between two points using Google Maps Android API v2

How can i show only those of my markers that are close to this path in a radius for example 500m ?

解决方案

You can use the PolyUtil.isLocationOnPath method from the Google Maps Android API Utility Library:

Computes whether the given point lies on or near a polyline, within a specified tolerance in meters. The polyline is composed of great circle segments if geodesic is true, and of Rhumb segments otherwise. The polyline is not closed -- the closing segment between the first point and the last point is not included.

public static boolean isLocationOnPath(LatLng point, List<LatLng> polyline, boolean geodesic, double tolerance)

You will need to iterate over your markers and make them visible or invisible depending on the returned value of PolyUtil.isLocationOnPath with your desired tolerance (500 in your example):

for(Marker marker : markers) {
    if (PolyUtil.isLocationOnPath(marker.getPosition(), yourRoutePath, false, 500)) {
        marker.setVisible(true);
    } else {
        marker.setVisible(false);
    }
}

这篇关于我如何在android地图中显示接近路径路径的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆