代码如下:
public Location getLocation() {// 获取Location通过LocationManger获取!
LocationManager locManger = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location loc = locManger.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (loc == null) {
loc = locManger.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
return loc;
}
public void LocationMethod() {// Location常用方法简介
Location loc = getLocation();
// loc.distanceTo(Location dest);float
// loc.getAltitude();double 海拔高度
// loc.getLatitude();double
// loc.getLongitude();double
// loc.getSpeed();float
}
要想使用Location服务,还必须添加Location的权限:uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/
OK,此文章内容比较简单!