如何知道我的位置是否等于固定位置
How to know if my location equal to a constant location
嗨,我是 android 的新手,如果设备的位置等于特定的 location.like,我会尝试设置一个字符串:
if (DeviceLocation == SpecificLocation) {
String s = "Location Find";
}
请帮忙。
您必须使用位置 class 将最后已知位置与您喜欢的位置进行比较。 (http://developer.android.com/reference/android/location/Location.html)
一开始你必须实现定位服务。
请参阅:http://developer.android.com/training/location/index.html 实施后,您将能够与您的位置进行比较。 (你需要知道你喜欢的位置的坐标)
要比较两个位置,您可以使用 distanceBetween() or distanceTo()。
他们将 return 两个位置之间的大致 米 距离。
例如:
float[] distance = new float[1];
Location.distanceBetween(lat, lon, currentLat, currentLon, distance);
if (distance[0] < 2.0) {
String s = "Location Found";
}
另一种选择是比较您的 Latitude
和 Longitude
个位置。
嗨,我是 android 的新手,如果设备的位置等于特定的 location.like,我会尝试设置一个字符串:
if (DeviceLocation == SpecificLocation) {
String s = "Location Find";
}
请帮忙。
您必须使用位置 class 将最后已知位置与您喜欢的位置进行比较。 (http://developer.android.com/reference/android/location/Location.html) 一开始你必须实现定位服务。 请参阅:http://developer.android.com/training/location/index.html 实施后,您将能够与您的位置进行比较。 (你需要知道你喜欢的位置的坐标)
要比较两个位置,您可以使用 distanceBetween() or distanceTo()。
他们将 return 两个位置之间的大致 米 距离。
例如:
float[] distance = new float[1];
Location.distanceBetween(lat, lon, currentLat, currentLon, distance);
if (distance[0] < 2.0) {
String s = "Location Found";
}
另一种选择是比较您的 Latitude
和 Longitude
个位置。