为什么MyLocationOverlay不起作用?

时间:2011-09-03 08:00:53

标签: android google-maps

在我的应用程序中,我希望看到当你在谷歌地图中走动时跟随你的小蓝点。下面是代码,但是我在任何地方都看不到蓝点,即使我将应用程序导出到手机中也是如此!

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;
    }
}

谢谢!

1 个答案:

答案 0 :(得分:3)

确保您的清单中有ACCESS_FINE_LOCATION权限。