我需要在移动时计算Gps位置并偏离某个位置。我尝试使用行车路线,但不推荐任何相似的东西都会很好。
答案 0 :(得分:1)
我不认为在移动中经常使用gps获取位置是可行的,因为它会消耗很多电池电量..,虽然为了检测偏差,我认为你需要在lat long的基础上手动计算它。
有关地点的更多信息,请查看此内容:
http://developer.android.com/guide/topics/location/obtaining-user-location.html
这个,
http://android-developers.blogspot.com/2011/06/deep-dive-into-location.html
答案 1 :(得分:0)
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
location.getLatitude();
location.getLongitude()
// what you want to do
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
Toast.makeText(LocationInfoActivity.this,
String.valueOf("onStatusChanged " + provider),
Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider) {
Toast.makeText(LocationInfoActivity.this,
String.valueOf("onProviderEnabled " + provider),
Toast.LENGTH_SHORT).show();
}
public void onProviderDisabled(String provider) {
Toast.makeText(LocationInfoActivity.this,
String.valueOf("onProviderDisabled " + provider),
Toast.LENGTH_SHORT).show();
}
};
try {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 10000, 1, locationListener);
// the 1 denotes meter (deviation)
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 10000, 1,
locationListener);
locationManager.requestLocationUpdates(
LocationManager.PASSIVE_PROVIDER, 10000, 1,
locationListener);
}
}
参考: http://developer.android.com/guide/topics/location/obtaining-user-location.html