1,获取LocationManager 对象
LocationManager locaManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
2,调用locationManager 中requuestLocationUpdates()函数
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// 当GPS locationProvider 可用时,更新位置
updateView(locManager.getLastKnownLocation(provider));
}
@Override
public void onProviderDisabled(String provider) {
updateView(null);
}
@Override
public void onLocationChanged(Location location) {
// 当GPS定位信息发生改变时,更新位置
updateView(location);
Log.d("UPDATElocation", " 00000000");
}
});
3,获取经纬度洗洗
private void updateView(Location newlocation) {
if (newlocation != null) {
Log.d("UPDATElocation", " 00000000");
StringBuilder sb = new StringBuilder();
sb.append("经度:");
sb.append(newlocation.getLongitude());
sb.append("\n纬度:");
sb.append(newlocation.getLatitude());
show.setText(sb.toString());
} else {
show.setText("xxx");
}
}
本文介绍了如何在Android中获取手机的位置信息,通过LocationManager对象调用requestLocationUpdates()函数监听GPS提供者的变化,当位置信息更新时,获取并显示经纬度坐标。
3088

被折叠的 条评论
为什么被折叠?



