【发布时间】:2011-12-11 18:06:55
【问题描述】:
由于某种原因,当我在 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();
}
}
【问题讨论】:
标签: android gps locationmanager locationlistener