Dear readers am back after a long time trying to complete what i started a few months back. This article is part 5 of the previous series but it doesn’t depend on the code of the previous articles, still they can be referenced to get a better understanding of configuring Google Maps for Android and learning the basic development of Google Maps for Android. The development environment stays the same as of the previous articles. No change in any of the configurations etc.

Please see the links for previous articles for basics of Google Maps for Android.

Objective of this article is to add multiple images to our Google Map Application for Android. I have taken a scenario where I have a list of coordinates of different cities of Pakistan and I want display an image on each city. Check the final output of this article so that you have an idea of what we will achieve at the end of this tutorial.

Multiple Images Displayed on our Android Google Maps Application.

Starting with the actual work, inside the main GoogleMapsAppActivity Class that extends MapActivity, add a Class lets say MirItemizedClass that extends ItemizedOverlay. This is a base class for an Overlay which consists of a list of OverlayItems. This handles sorting north-to-south for drawing, creating span bounds, drawing a marker for each point, and maintaining a focused item. It also matches screen-taps to items, and dispatches Focus-change events to an optional listener.

We have to set the bounding rectangle of the drawable that we add to our ItemizedOverlay. The defaultMarker is a Drawable that is drawn on every OverlayItem that we add to our ItemizedOverlay. To do this we have to use boundCenterBottom or boundCenter or we can use the setBounds method to get the job done. So we have used boundCenterBottom(defaultMaker). To add multiple overlays we have added a List of OverlayItem and used that in the createItem and size methods of our ItemizedOverlay Class. To add the OverlayItems to our internal list we have added the method addOverlayItem(OverlayItem overlayItem).

Now we will use the functionality of MirItemizedOverlay Class in the onCeate method of our main GoogleMapsAppActivity Class.

We will create instances of Drawable and MirItemizedOverlay to retrieve the image from our res/drawable folder and to supply that image to the our ItemizedOverlay Class.

I already designed a class with multiple location selection, my question is how to add multiple location information into database? i.e. suppose I want 5 location selected, how am i going to add this info in database

Dear Nauman,
I have done it.. of course after a lot of trial and errors. 😉
I got it implemented onTap() method. in which par tap i get my class onDraw method to draw png resource on map and in onTap() method I implemented web-service which saves information in database and retrieve information in an other class which passes these coordinates to again onDraw method of that class.

I will wait for your post, but I still have a question.
I wanna find the method to show a shortest direction road between two Geopoints (not a straight line). Can you show me some documents about this?
Thanks Mir

First of all thank you very much for the complete and clear tutorials in the google maps topic. I am creating an app for a school project of mine and i found these tutorials very helpful but of course i had smth to ask you 😛

1st: Making all these classes part of the same file is smth mandatory in order to exploit the context of googleMapsActivity class?
2nd:My idea in the project is to search for 2 different locations of interest in the map. I want to create 2 diff markers for the various points and depending on what the user wants to search for , display the respective markers. IS this possible ? If yes , do I need 2 diff overlays or can i work with various methods?

Thx for any response and i’m sorry if the questions are too obvious. (i’m a beginner in android :P)

its not mandatory to make all classes part of the same file. but i have done it so that my readers can easily understand the idea and flow.
u can display as many markers as u want and u don’t need 2 overlays, one is enough. secondly searching two location is possible if u have the coordinates. u can easily put markers on those coordinates.

Check the android version than check the google Maps Api versions on ur phone and on ur emulator. secondly if the device loads the map but the screen is empty grid than that is a problem of Google Maps APi Key.

Thank sir to answer me i Check my android version and the google Maps Api versions its same but the problem not show me the map just the star and if you ask me about android key i register it in Google map after get MD5 .what do you suggest to me I do.

Thank sir you support me but i discovered what my fault after export to android apk not the same bath and i current this ,so now every think is ok
i know i tired you but can you help me hoe to save this location
( 33695043, 73000000, “Islamabad”);
(33480000, 73000000, “Some Other Pakistani City”);
(33380000, 73000000, “Some Other Pakistani City”);
in data base i want to bottom search for any location for example write in this bottom Islamabad .the result show me just one star.
With my best wishes .

Dear mustafa,
saving data on device in database or in flat files is a completely separate domain. the above series or articles only show the basics for google maps for android. i have written application on saving data in databases as well as in flat text files. but have not written tutorial for them yet. i ll try to publish their tutorial ASAP.

hi Mir how are you i hope you are fine. Sir i want ask you how can i show my location automatically on the same Google map(Tutorial Part 5) i mean use Gps . For example i show my current location when i go to any place at Luminous arrow

Hello! Thenk you so much for this tutorial 🙂
I have a question about adding photos to google maps. How is it possible to add a photo which is sored on the phone to the map? I would be grateful for the link on methods how it is possible. Thank you.

Thank you for teh answer. This tutorial was very helpful 🙂
I want the user to choose the photo from teh photos which are stored on the phone and to upload this chosen photo. In the tutorial there was this specific photo. Or am I mistaking?

well the above tutorial’s main focus is on the basic functionality of google maps and not reading contents(images,text files etc) from any location(photo galary, sd card etc) from the device. thats why i have copied the image in the package and hardcoded it in the source. to dynamically get contents from any location from the device will need an all new tutorial. i ll write something about it. soon. Each article here will not provide you everything that u need, but chunks that can be used from different programs to get wat u need. I ll write something about reading contents dynamically from the device soon. this could be nice thing to write about. thanks for pointing it out. 🙂

i have not used two overlays so far, but i think one can do the job than why use two. still u can give it a try and post ur experience under this thread so that every1 knows. secondly yes u can save the places in sqlite or simple comma seperated txt files or xml files. depends wat u will prefer and how u will retrieve data back from them.

Mir Nauman Tahir, i have tried your code and after few changes able to run and getting each and everything, but need to add location name whenever user touch an overlay item, how can we add location name on overlay items…..Thanks

mapactivity could’nt get connection factory client ,can you help me for this error,when i open the app map comming out and didn’t show the overlays that i added,bt in logcat i got the real output,only thing is didnt visible at the map.plzzz hlp

Good afternoon. Thanks for the tutorial, it works. Posdkazhite, please, is it possible somehow to add markers, if one is not aware of them? That eats create a variable, for example, the user will select a number of 5 or 10, and the show, or 5, or 10 markers. Is this possible?

Thanks..
I want to draw a rote where the user is during trip,,,but I couldn’t find a way..So I will try to create the route according to the multiple cursor(make the cursor circle image or point) ..So I’ve included GPS ,So the emulator draws but not all times …Can you help me?