由于某种原因,当我在requestLocationUpdates()方法之后添加removeUpdates()时,我根本没有获得任何位置数据。 我没有正确取消订阅吗?
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 5000, 1, mlocListener);
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 5000, 1, mlocListener);
mlocManager.removeUpdates(mlocListener);
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
String text = "My current location is: " +
"Latitude = " + loc.getLatitude() +
"Longitude = " + loc.getLongitude();
System.out.println("FINISHED:");
Toast.makeText( getApplicationContext(),
text,
Toast.LENGTH_SHORT).show();
}
}