使用GPS获取当前位置时,不显示地图

时间:2012-10-31 05:37:20

标签: android map gps wifi

我面临一个奇怪的问题。当我使用WIFI时,我的应用程序在地图上显示当前位置,但当我关闭WIFI以使用GPS检查时,它仍显示当前位置但不显示地图。它使地图消失并显示当前位置。有人告诉我它为什么会发生?这是我的代码:

@Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        mapView = (MapView) findViewById(R.id.mapview);

        mapView.setBuiltInZoomControls(true);

        mapController = mapView.getController();
        me = new MyLocationOverlay(this, mapView);
        me.enableMyLocation();
        mapView.getOverlays().add(me);
        mapController.setZoom(10); 
        mapView.invalidate();

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    //  locationManager.requestLocationUpdates(
      //  LocationManager.NETWORK_PROVIDER, 0, 0, new GeoUpdateHandler());

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 0, 0, new GeoUpdateHandler());

    }

    @Override
    protected void onDestroy() {
        me.disableMyLocation();
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
        me.disableMyLocation();
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    public class GeoUpdateHandler implements LocationListener {

        // @Override
        public void onLocationChanged(Location location) {
            int lat = (int) (location.getLatitude() * 1E6);
            int lng = (int) (location.getLongitude() * 1E6);
            GeoPoint point = new GeoPoint(lat, lng);
            Toast.makeText(getApplicationContext(), "lat and lng"+lat+lng  , Toast.LENGTH_SHORT).show();
            mapController.setZoom(18);
            mapController.animateTo(point); // mapController.setCenter(point);
            mapView.invalidate();



        }

1 个答案:

答案 0 :(得分:0)

GPS与互联网无关,但如果您想显示MAP,那么您就拥有互联网......您可以在没有互联网的情况下获得GPS .....所以无需担心