0

我正在尝试在图片ImageView的帮助下创建一个MapView

像这样

伙计们请给我一些想法如何做到这一点。

4

2 回答 2

3

如果你想要一个静态地图,你可以和我一样:

http://maps.google.com/maps/api/staticmap?center=-15.800513%2C-47.91378&zoom=16&format=png&maptype=roadmap&mobile=false&markers=|color:%23128DD9|label:Marker|-15.800513%2C-47.91378&size=1000x400&key=&sensor=false

更改参数

  1. ?center=这会告诉你图像的中心应该在哪里
  2. label:Marker标记应出现的位置。

将此图像加载到ImageView

public static Bitmap loadBitmap(String url) {
    Bitmap bitmap = null;
    InputStream in = null;
    BufferedOutputStream out = null;

    try {
        in = new BufferedInputStream(new URL(url).openStream(), IO_BUFFER_SIZE);

        final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
        out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
        copy(in, out);
        out.flush();

        final byte[] data = dataStream.toByteArray();
        BitmapFactory.Options options = new BitmapFactory.Options();
        //options.inSampleSize = 1;

        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
    } catch (IOException e) {
        Log.e(TAG, "Could not load Bitmap from: " + url);
    } finally {
        closeStream(in);
        closeStream(out);
    }

    return bitmap;
}

这个方法将返回一个Bitmap来设置它BitmapImageView就像这样:

 ImageView img = (ImageView)findViewById(R.id.imageView1);
 Bitmap b = loadBitmap(urlToTheImage);
 img.setImageBitmap(b);
于 2012-10-10T10:17:01.843 回答
1

我不完全确定您的意思,但从外观上看,您需要 Google Static Maps API。

https://developers.google.com/maps/documentation/staticmaps/

当您为其提供纬度、经度等时,这将生成地图图像。然后您可以根据需要在 ImageView 中使用它。

优点是你不必创建昂贵的 MapView,但它不会是交互式的

于 2012-10-10T10:02:14.273 回答