2012-10-31 266 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

好的,謝謝分享這些信息。 –