1

当我在模拟器上运行我的应用程序时,Google Maps API 运行得非常好,但是当我放大它时,它不会像网络版本那样聚焦或呈现。

有任何想法吗?

这是我的代码:

@Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        setContentView(R.layout.map);

        Button openDrawer = (Button) findViewById(R.id.openDrawer);
        openDrawer.setOnClickListener(this);

        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
        MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable, this);

        GeoPoint point = new GeoPoint(19240000,-99120000);
        OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
    }
4

2 回答 2

0

你试过下面的代码吗???

MapController controller = mapView.getController();
controller.setZoom(15);
controller.setCenter(point);
于 2012-09-28T13:42:45.293 回答
0

我相信你需要做的就是打电话mapView.invalidate(),我设置的地图和你的有点不同,我复制了下面的代码以供参考:

LocationManager jLocManager;
MapController mController;
GeoPoint geoP;
MapView mapView;
MyLocationOverlay myLocOverlay;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maps);

    try {
        JJMapsInitialize();
    }catch(Exception e){
        Log.e("JJMapsInitialize", "FAILED: " + e.getMessage());
    }

    myLocOverlay = new MyLocationOverlay(this, mapView);
    myLocOverlay.enableMyLocation();
    mapView.getOverlays().add(myLocOverlay);

}

public void findMyLocation() {
    LocationManager jLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // 35000 is 35 seconds to find location && 10 is the minimum distance in meters
    jLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 10, this.jLocListener);
    jLocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 3000, 10, this.jLocListener);
}

private void JJMapsInitialize() {
    try { 
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.displayZoomControls(true);
        mapView.setBuiltInZoomControls(true);
        mController.animateTo(geoP);
        mController.setZoom(10);
        mapView.invalidate();
    } catch(Exception e) {
        Log.e("JJMapsInitialize", "FAILED: " + e.getMessage());
    }

    try {
        findMyLocation();
    } catch (Exception e) {
        Log.e("findMyLocation", "FAILED: " + e.getMessage());
    }
}

正如你所看到的,我调用了初始化方法,在该方法中我使用控件设置了我MapView的控件,使其无效,然后添加我的叠加层。


编辑

jLocListener只是我的LocationListener()- 我的名字以“j”开头,所以我通常在命名约定中使用我的首字母或两个首字母。

public LocationListener jLocListener = new LocationListener() {
        //class findMe implements LocationListener {
        public void onLocationChanged(Location location) {
            try {
                lat = location.getLatitude();
                lon = location.getLongitude();
            } catch (Exception e) {
                Log.e("onLocationChanged", "FAILED: " + e.getMessage());
            }
        }
        public void onProviderDisabled(String provider) {
            Log.i("LocationListener", "onProviderDisabled");
        }
        public void onProviderEnabled(String provider) {
            Log.i("LocationListener", "onProviderEnabled");
        }
        public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.i("LocationListener", "onStatusChanged");
        }

    };
于 2012-09-28T14:21:52.023 回答