为什么MyLocationOverlay不起作用

为什么MyLocationOverlay不起作用

在我的应用程序中,当您在Google地图中走动时,我想看到跟随您的小蓝点。下面是代码,但是即使将应用程序导出到手机中,我也看不到任何蓝点!

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


谢谢!

最佳答案

确保清单中具有ACCESS_FINE_LOCATION权限。

关于android - 为什么MyLocationOverlay不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7291909/

10-09 07:01