2012-10-31 133 views
0

我正面临一个奇怪的问题。当我使用WIFI时,我的应用会在地图上显示当前位置,但是当我关闭WIFI以使用GPS进行检查时,它仍显示当前位置,但不显示地图。它会使地图​​消失并显示当前位置。有人告诉我为什么会发生这种情况?这里是我的代码:使用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(); 



     } 

回答

0

GPS是不相关的互联网,但如果你想查看地图让您拥有一个互联网.....你可以得到GPS没有互联网.....所以没必要担心

+0

你的意思是它不会显示任何使用GPS的地图?我必须向用户展示他当前的位置,无论他使用的是什么(WIFI或GPS) –

+0

您可以在没有互联网的情况下获得curret位置,但要显示地图,您必须有互联网(WIFI或GPS) –

+0

好的,谢谢分享这些信息。 –