之间的距离或其他检查当前位置是否在标记半径内的方法
distanceBetween or other way to check if current position is in radius to marker
我想检查用户的当前位置是否在某个标记的特定半径范围内。我应该用 distanceBetween()
来做吗?
我必须传递什么参数才能传递此函数,结果究竟是什么意思?
LatLng markerPosition = marker.getPosition();
myLocation = locationManager.getLastKnownLocation(provider);
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();
distanceBetween(???);
public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results) {
}
你可以简单的使用
distanceTo(Location location)
从位置 class 执行此操作,例如:
Location makerLoc = new Location("marker");
markerLoc.setLatitude(markerPosition.latitude);
markerLoc.setLongitude(markerPosition.longtitude);
float meters = myLocation.distanceTo(markerLoc);
请使用 Google 地图工具 Library
这个库提供了非常简单的距离计算,就像您需要的那样
例如:
computeDistanceBetween() – Returns the distance, in meters, between two
latitude/longitude coordinates.
computeHeading() – Returns the bearing, in degrees, between two
latitude/longitude coordinates.
computeArea() – Returns the area, in square meters, of a closed path on the
Earth.
interpolate() – Returns the latitude/longitude coordinates of a point that
lies a given fraction of the distance between two given points. You can use
this to animate a marker between two points, for example.
我想检查用户的当前位置是否在某个标记的特定半径范围内。我应该用 distanceBetween()
来做吗?
我必须传递什么参数才能传递此函数,结果究竟是什么意思?
LatLng markerPosition = marker.getPosition();
myLocation = locationManager.getLastKnownLocation(provider);
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();
distanceBetween(???);
public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results) {
}
你可以简单的使用
distanceTo(Location location)
从位置 class 执行此操作,例如:
Location makerLoc = new Location("marker");
markerLoc.setLatitude(markerPosition.latitude);
markerLoc.setLongitude(markerPosition.longtitude);
float meters = myLocation.distanceTo(markerLoc);
请使用 Google 地图工具 Library
这个库提供了非常简单的距离计算,就像您需要的那样
例如:
computeDistanceBetween() – Returns the distance, in meters, between two
latitude/longitude coordinates.
computeHeading() – Returns the bearing, in degrees, between two
latitude/longitude coordinates.
computeArea() – Returns the area, in square meters, of a closed path on the
Earth.
interpolate() – Returns the latitude/longitude coordinates of a point that
lies a given fraction of the distance between two given points. You can use
this to animate a marker between two points, for example.