我有一个关于Android中LocationListener的一般问题.也许这是关于Android或Java事件的一般情况,但不确定.
似乎有一百万种方法来设置LocationListener,它们看起来都很丑陋(主要是因为缺乏可重用性).这是android在这里找到的一个例子:
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是,我真的很惊讶这是编写OOP代码的标准方法......
我真正希望看到的是一种实现LocationListener 的简单可重用方法.有人知道如何做到这一点的简单教程吗?我的目标是能够轻松实现任何需要使用gps信息更新的活动......也许是服务?谢谢!
| 归档时间: |
|
| 查看次数: |
17898 次 |
| 最近记录: |