检查给定的纬度,经度点是否位于从A到B的路线上

时间:2015-03-08 04:20:54

标签: android google-maps google-play-services google-maps-android-api-2 google-maps-api-2

我正在和Android app一起工作,我需要找出一个给定的纬度,经度点是否位于从A到B的路线上。

我正在使用LatLngBounds。当路线仅从SouthWest到NothEast但它从不适用于其他路线(NE到SW或SE到NW或NW到SE)时,它可以工作。它给出了NW到SW的错误结果,以及SE到NW或NW到SE的错误。

我尝试将LtLngBounds.Builder()用于其他三种情况,即NE到SW或SE到NW或NW到SE。但是代码对他们没有用。以下是我使用的代码。

LatLngBounds.Builder b_builder = new LatLngBounds.Builder();
b_builder.include(se_latlng); //start point
b_builder.include(nw_latlng); //end point 
LatLngBounds b = b_builder.build(); //I am building the bound here
boolean present3 = b.contains(mid_latlng1); //Checking if this point lies along the route
boolean present4 = b.contains(mid_latlng2); //Checking if this point lies along the route

以上两种情况,我都认为b.contains(NE到SW或SE到NW或NW到SE)都是如此。但事实上,这些点中只有一个位于该路线上。我对其余的案例也做了同样的尝试但是我总是变得如此,即使这个点位于或沿着路线倾斜。

LatLngBounds适用于SouthWest到NorthEast。任何人都可以帮助我找出一个点是否沿着从A到B的其他方向(NE到SW或SE到NW或NW到SE)的路线。

1 个答案:

答案 0 :(得分:0)

已经有了这个任务的lib。从Polyline中删除LatLng并使用isLocationOnPath

相关问题