2014-09-29 80 views
-1

我想顯示地圖快照而不在UI上顯示實際地圖。在地圖加載到用戶界面之後,我獲得了快照。所以我只想知道是否可以在後臺加載地圖並獲取快照並在用戶界面上顯示該快照,現在就像google一樣。Android:如何獲取地圖快照?

+0

不,我不認爲它的possbile,你必須顯示視圖來獲取快照 – 2014-09-29 10:36:21

回答

2

使用此代碼,以靜態地圖

String url = String.format(
     "http://maps.google.com/maps/api/staticmap?center=%f,%f&zoom=16&size=%dx300&sensor=false&key=%s", 
     lat, 
     lon, 
     imageWidth, 
     context.getResources().getString(R.string.mapApiKey2) 
    ); 

    Bitmap bmp = null; 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpGet request = new HttpGet(url); 

    InputStream in; 
    try { 
     in = httpclient.execute(request).getEntity().getContent(); 
     bmp = BitmapFactory.decodeStream(in); 
     in.close(); 
    } catch (IllegalStateException e) { 
     e.printStackTrace(); 
    } catch (ClientProtocolException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    return bmp; 

替代緯度,經度和imageWidth,這將返回一個bmp。 使用此代碼創建一個函數