How to display static google map on android imageview?

后端 未结 8 1944
长情又很酷
长情又很酷 2020-12-04 06:33

I want to display a static google map on an imageview. Something similar to \"Whatsapp\" showing while share the location. How can I do this?

8条回答
  •  天涯浪人
    2020-12-04 06:57

    public static Bitmap getGoogleMapThumbnail(double lati, double longi){
            String URL = "http://maps.google.com/maps/api/staticmap?center=" +lati + "," + longi + "&zoom=15&size=200x200&sensor=false";
            Bitmap bmp = null;
            HttpClient httpclient = new DefaultHttpClient();   
            HttpGet request = new HttpGet(URL); 
    
            InputStream in = null;
            try {
                in = httpclient.execute(request).getEntity().getContent();
                bmp = BitmapFactory.decodeStream(in);
                in.close();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
            return bmp;
        }
    

提交回复
热议问题