它不清楚如何使用位置侦听器。如何使用位置监听器?
难道我这样做:
public Location actualLocation;
private class mLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
actualLocation = location;
}
public void onStatusChanged(String s, int i, Bundle b) {
}
public void onProviderDisabled(String s) {
}
public void onProviderEnabled(String s) {
}
}
//Middle of code
currentLatitude = actualLocation.getLatitude()
currentLongitude = actualLocation.getLongitude()
或本:
public Location actualLocation;
private class mLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
}
public void onStatusChanged(String s, int i, Bundle b) {
}
public void onProviderDisabled(String s) {
}
public void onProviderEnabled(String s) {
}
}
//Middle of code
actualLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
currentLatitude = actualLocation.getLatitude()
currentLongitude = actualLocation.getLongitude()
有使用变量并没有在这个代码片段声明。这是有目的的。为了简单起见,我缩短了代码。
更新: 我的问题是:?我使用getLastKnow位置还是手动保存每次运行的位置? ¿工作原理是否一样?
你想使用LocationListener实现什么 –