android – 如何让我的谷歌地图放大到我当前的位置?

嗨,我想让我的地图放大到我当前的位置.
当前通过向仿真器发送lat和long来定义当前位置.
我该怎么做呢?

我目前的mapactivity.java

public class MapsActivity extends MapActivity {

    private MapView mapView;
    private MyLocationOverlay myLocOverlay;
    MapController mc;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapactivity);
        initMap();
        initMyLocation();


    }

    /**
     * Initialise the map and adds the zoomcontrols to the LinearLayout.
     */
    private void initMap() {
        mapView = (MapView) findViewById(R.id.mapView);

        View zoomView = mapView.getZoomControls();
        LinearLayout myzoom = (LinearLayout) findViewById(R.id.zoom);
        myzoom.addView(zoomView);
        mapView.displayZoomControls(true);
        mapView.getController().setZoom(17);
    }

    /**
     * Initialises the MyLocationOverlay and adds it to the overlays of the map
     */
    private void initMyLocation() {
        myLocOverlay = new MyLocationOverlay(this,mapView);
        myLocOverlay.enableMyLocation();
        mapView.getoverlays().add(myLocOverlay);

    }

    @Override
    protected boolean isRoutedisplayed() {
        return false;
    }

谢谢.

最佳答案
您需要实现onLocationChanged().在我的代码中,我也在这里添加了叠加层.您至少需要使用当前位置setCenter()

public void onLocationChanged(Location location) {

   Listetoverlays();
   myLocOverlay = new MyLocationOverlay(this,mapView);
   overlays.add(myLocOverlay);
   myLocOverlay.enableMyLocation();*

   // definitely need what's below
   int lat = (int) (location.getLatitude() * 1E6);
   int lng = (int) (location.getLongitude() * 1E6);
   GeoPoint point = new GeoPoint(lat,lng);
   mc.setCenter(point);
   mapView.invalidate();

}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...