Android – MapView contained within a Listview

To post an alternate solution to a rather old answer (over 2 years actually), but I thought this might help someone who might stumble on this post like I did.

NOTE: This might be useful for someone who simply needs to display the location in a “Map” but does not need to interact with it in the ListView. The actual Map can be displayed on say, a details page, after clicking on an item in the ListView

As already pointed out by @CaseyB, MapView is kind of a heavy view. To counter that aspect (and to make life a little but easier for me 😉 ), I chose to build an URL like you would for a static Google Map, using several parameters that are necessary for my application. You can get more options here: https://developers.google.com/maps/documentation/staticmaps/

First, when I am constructing the data for my ListView, I pass data such as the latitude and longitude to a string with some static variables taken from the link mentioned above. I get my co-ordinates from the Facebook API.

The code I use to construct the link:

String getMapURL = "http://maps.googleapis.com/maps/api/staticmap?zoom=18&size=560x240&markers=size:mid|color:red|"  
+ JOLocation.getString("latitude") 
+ "," 
+ JOLocation.getString("longitude") 
+ "&sensor=false";

The above constructed URL, when used in a browser, returns a .PNG file. Then, in my adapter for the activity, I use @Fedor’s Lazy Loading to display the image generated from the URL contructed earlier to display in the custom ListView. You can of course choose your own method to display this Map (Map’s image actually).

An example of the final result.

enter image description here

Currently, I have about 30 odd Checkin Maps (I use it in conjunction with the Facebook SDK) in this ListView, but users can have 100’s of them and there have been absolutely no reports of it slowing down.

I suspect, this might not help the OP considering the time that has passed since the question, but hope it helps other users landing on this page in the future.

Leave a Comment