Android MapView: how to save position/zoom after animateTo and zoom?
Is there anyway I can get some position information for animateTo or current center of the MapView so I can re开发者_StackOverflowstore it later? Also the same for zoom level?
Thanks!
Use sharedPreferences , see this example´s GetZoom() and SaveZoom() functions you can use something similar
static final String PREFS_Zoom = "PREFS_Zoom";
private String zoomlevel;
private int Default_zoomlevel=100;
private void GetZoom(){
try{
SharedPreferences settings = getSharedPreferences(PREFS_Zoom,0);
zoomlevel = settings.getString("zoom_level","");
if (zoomlevel.length() >0)
Default_zoomlevel = Integer.parseInt(zoomlevel);
else
Default_zoomlevel =100;
}catch(Exception ex){
Log.e("******ZOOM ! ", "Exception GetZoom() ::"+ex.getMessage());
}
}
private void SaveZoom(){
try{
SharedPreferences settings = getSharedPreferences(PREFS_Zoom,0);
SharedPreferences.Editor editor = settings.edit();
Default_zoomlevel = (int) (mWebView.getScale() *100);
editor.putString("zoom_level",""+ Default_zoomlevel);
editor.commit();
}catch(Exception ex){
Log.e("******ZOOM ! ", "Exception SaveZoom() ::"+ex.getMessage());
}
}
UPDATE::
MapView Class has a method getZoomLevel() that returns the current zoom level of the map. for GeoPosition check getLatitudeSpan() and getLongitudeSpan() methods
精彩评论