0

我一直在尝试从我的位置管理器中删除位置更新,但是即使在调用 removeupdates 之后 GPS 符号也会持续显示。我已确保传递了正确的侦听器变量名称,并为侦听器更新执行了代码。我只想找到用户的位置一次。

谢谢

public class MapActivity extends FragmentActivity implements OnInfoWindowClickListener, OnCameraChangeListener {

    Map<Marker, Integer> markers = new HashMap<Marker, Integer>();
    VenueManager venueManager;
    GoogleMap map;
    long last_map_refresh = 0;
    Button search_btn;
    CameraPosition previous_position = null;
    private LocationManager locationManager;
    private static final long MIN_TIME = 400;
    private static final float MIN_DISTANCE = 1000;
    private ProgressDialog loading;
    private Button add_venue;
    SharedPreferences sharedPreferences;
    private LatLng user_position = null;
    private NetworkManager network_manager;
    private Boolean first_map_render = false;
    private LocationListener location_listener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);

        locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

        if( !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) ) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MapActivity.this);
            builder.setTitle("GPS not enabled");  // GPS not found
            builder.setMessage("This application requires you to enable GPS location settings. We recommend that you enable 'Use wireless networks' and 'Use GPS satellites'. Would you like to enable this setting now?"); // Want to enable?
            builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    finish();
                    MapActivity.this.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }
            });
            builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent home_intent = new Intent(MapActivity.this, HomeActivity.class);
                    startActivity(home_intent);
                    Toast.makeText(MapActivity.this, "You will not be able to use the map features of this application until you enable gps settings", Toast.LENGTH_LONG).show();
                    finish();
                }
            });

            builder.create().show();
            return;
        }
        else
        {
            network_manager = new NetworkManager();

            location_listener = new LocationListener() {
                public void onLocationChanged(Location location) {
                    // TODO Auto-generated method stub

                    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
                    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 16);
                    map.animateCamera(cameraUpdate);
                    draw_map(new CameraPosition.Builder().target(new LatLng(location.getLatitude(), location.getLongitude())).build());
                    user_position = latLng;

                    locationManager.removeUpdates(location_listener);
             };

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, location_listener);
}
}
4

1 回答 1

2

首先,使用时LocationManager.NETWORK_PROVIDER您根本不应该看到 GPS 符号。

我看到您正在使用 Google Maps Android API v2,所以我的猜测超出了您放在这里的代码

map.setMyLocationEnabled(true);

它显示蓝点并在显示Activity时不断更新它MapFragment/ MapView

于 2013-07-03T19:01:38.460 回答