开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜