您好,我想让我的 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/