2011-09-03 52 views
1

在我的應用程序中我希望看到隨着你在谷歌地圖中漫步的小藍點。下面是代碼,但是我沒有在任何地方看到藍點,即使將應用程序導出到我的手機時也是如此!爲什麼MyLocationOverlay不起作用?

public class UCLAProjectActivity extends MapActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     MapView mapView = (MapView) findViewById(R.id.mapView); 
     MapController mc = mapView.getController(); 
     int maxLat = (int) (34.07687 * 1E6); 
     int maxLon = (int) (-118.438239 * 1E6); 
     int minLat = (int) (34.06489 * 1E6); 
     int minLon = (int) (-118.452358 * 1E6); 
     List <Overlay> overlays = mapView.getOverlays(); 
      // "this" refers to your activity 
      MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView); 
      myLocationOverlay.enableMyLocation(); 
      overlays.add(myLocationOverlay); 

     mc.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon)); 

     mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLon + minLon)/2)); 
    } 

    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 
} 

謝謝!

回答

3

確保您的清單中有ACCESS_FINE_LOCATION權限。

+0

哈,你說得對。謝謝一堆! –