安卓设备定位与位置跟踪开发指南
1. 确定设备当前位置
在开发安卓应用时,若要获取设备的当前位置,需要借助 LocationManager 。以下为详细步骤:
- 获取LocationManager引用 :
- 由于 LocationManager 是访问定位服务的入口,应用需获取其引用。可通过调用 Activity.getSystemService(LOCATION_SERVICE) 实现。
- 通常在 Activity 的 onCreate() 方法中进行此操作,示例代码如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.current_location);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
latitudeValue = (TextView) findViewById(R.id.latitudeValue);
longitudeValue = (TextView) findViewById(R.id.longitudeValue);
providerValue = (T
超级会员免费看
订阅专栏 解锁全文
661

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



