如何在提供一组位置后获取GOOGLE地图图像?

问题描述 投票:0回答:1

目前我正在使用GOOGLE Static Map API。但是我的URL超过了为搁浅URL分配的最大字符数。没有GOOGLE Static Map API,有没有办法做到这一点?

android google-static-maps
1个回答
0
投票

您无法通过提供一组位置列表来获取静态地图列表。那将为您提供JSON / XML响应。要获得4年前我在解决方案下使用的某个位置的静态地图。我不确定任何更新的解决方案。看看这个网址

http://maps.google.com/maps/api/staticmap?center=LATITUDE,LONGITUDE&zoom=15&size=200x200&sensor=false

url在这里是棘手的部分,它实际上返回了所请求的lat的静态图像,lang。你也可以指定你想要的图像尺寸,这里我使用200x200。您也可以使用任何ImageLoader,即Glide,picasso来加载该图像

public Bitmap getMapImage(double latitude, double longitude) {

    Bitmap bmp = null;
    InputStream inputStream = null;
    try {
        java.net.URL mapUrl = new URL("http://maps.google.com/maps/api/staticmap?center="+latitude+","+longitude+"&zoom=15&size=200x200&sensor=false");

        HttpURLConnection httpURLConnection = (HttpURLConnection) mapUrl.openConnection();

        inputStream = new BufferedInputStream(httpURLConnection.getInputStream());

        bmp = BitmapFactory.decodeStream(inputStream);

        inputStream.close();
        httpURLConnection.disconnect();

    } catch (IllegalStateException e) {
        Log.e("tag", e.toString());
    } catch (IOException e) {
        Log.e("tag", e.toString());
    }

    return bmp;
}
© www.soinside.com 2019 - 2024. All rights reserved.