0

I am trying to create a ImageView with help of MapView something like in pic:

like this

Guys please give me some idea how to do this.

Community
  • 1
  • 1
Yasir Khan
  • 2,413
  • 4
  • 20
  • 26
  • you can use mapview only with size as per your image size instead of using image view – Syn3sthete Oct 10 '12 at 10:00
  • One way woul be to create a regular `MapView`, then get its view as a bitmap and display that bitmap. Have a look at [this question](http://stackoverflow.com/questions/2801116/converting-a-view-to-bitmap-without-displaying-it-in-android) for how to get a bitmap of a view. – Aleks G Oct 10 '12 at 10:00

2 Answers2

3

If you want a static map, you can just do the same as me:

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

Change the parameters

  1. ?center= which will tell you where the center of the image shoud be
  2. label:Marker The position where the marker should appear.

To load this image to an 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;
}

This method will return a Bitmap to set this Bitmap in the ImageView just do like this:

 ImageView img = (ImageView)findViewById(R.id.imageView1);
 Bitmap b = loadBitmap(urlToTheImage);
 img.setImageBitmap(b);
Tobias Moe Thorstensen
  • 8,861
  • 16
  • 75
  • 143
1

I'm not exactly sure what you mean, but from the looks of it you want the Google Static Maps API.

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

This will generate an image of a map when you give it the latitude, longitude etc. You can then use this in an ImageView as you require.

The advantage is that you don't have to create an expensive MapView, but it will not be interactive

Joss Stuart
  • 1,856
  • 1
  • 17
  • 19
  • thanks i was in such a hurry but you got me this is what i was looking for thanks, Will accept this answer within a min. – Yasir Khan Oct 10 '12 at 10:11