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

标签 android google-maps-android-api-1

您好,我想让我的 map 放大到我当前的位置。 当前位置当前通过向模拟器发送纬度和经度来定义。 我该怎么做呢?

我当前的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;
    }

谢谢。

最佳答案

尝试在您的 initMyLocation 代码末尾添加:

controller = mapView.getController();
mMyLocOverlay.runOnFirstFix(new Runnable() {
            public void run() {
                controller.setZoom(17);
                controller.animateTo(mMyLocOverlay.getMyLocation());
            }
        });

您可以从 initMap 方法中删除这一行:

mapView.getController().setZoom(17);

让我知道是否可行

蒙古包

关于android - 我如何让我的谷歌地图放大到我当前的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4146848/

相关文章:

javascript - 功能检测自动播放 HTML5 音频 - 移动浏览器上的音频

java - Robolectric:在我的案例中运行处理程序的循环程序

android - Android onResume后ListView为空

android - 如何在 Xamarin.Forms 中隐藏 Android ActionBar?

java - Vitamio 示例错误 - java.lang.UnsatisfiedLinkError : Couldn't load vinit findLibrary returned null

android-studio - 错误 : Please select Android SDK in Android Studio 2. 0

android - Google Maps Android API - 样式化 map

android - 修复 debug.keystore 以使用 ADT 22 和 Google Maps v1 API key