当我在我的模拟器上运行我的应用时,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);
}
答案 0 :(得分:0)
MapController controller = mapView.getController();
controller.setZoom(15);
controller.setCenter(point);
答案 1 :(得分: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");
}
};