我正在开发一款使用GPS的Android应用程序。我想知道是否有一种方法,如果“新位置”(点C)离线段AB太远,我可以丢弃GPS位置数据。我正在使用在维基百科上找到的“点到线段”公式。
到目前为止,当我尝试使用纬度和经度坐标时,我的代码返回NaN。
到目前为止,当我尝试使用纬度和经度坐标时,我的代码返回NaN。
private void verifyGPSLocation(Location start, Location end, Location current){
final double errorValue = 0.0000216;
double normalLength = Math.hypot(end.getLatitude() - start.getLatitude(), end.getLongitude() - start.getLongitude());
double ret = Math.abs(((current.getLatitude() - start.getLatitude()) * (end.getLongitude() - start.getLongitude()) - (end.getLatitude() - start.getLatitude()))/normalLength );
Log.e("Coooooord", normalLength+"--"+ret);
}
这是我的第一篇文章,请告诉我是否做得正确或者提供足够的信息。感谢您的帮助,我喜欢这个网站!
Location.distanceTo()
实际上在内部执行了相同的操作,你可以在这里看到:http://developer.android.com/reference/android/location/Location.html#distanceTo(android.location.Location)。因此,你可以使用其中任何一个,或者自己手动实现。 - jbx