2014-09-29 49 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。 使用此代码创建一个函数