views:

246

answers:

2

I can't beleive there's no easy way to do such a basic thing like this... I want to show a popup/baloon (a LinearLayout) after user clicks on a map marker (something smilar to what is in Google Maps app). It should move with the map, when the user scrolls the map. What is the best way to do this?

One idea is to have the LinearLayout in my Activity's root layout and show it when needed. But how to make it move with the map?

Another way to do that may be to create an Overlay that draws the LinearLayout in onDraw and gives the layout touch events. Is this possible?

A: 

The way I did is:

Put the markers at required GeoPoints by subclassing ItemizedOverlay, as described in http://developer.android.com/guide/tutorials/views/hello-mapview.html

Create a popup View by inflating from the layout:

View popUp = getLayoutInflater().inflate(R.layout.map_popup, map, false);

Use MapView.LayoutParams to position the popup with respect to GeoPoint in the ItemizedOverlay< OverlayItem >::onTap method. Popup will scroll automatically (without any additional code) when user scrolls the map. Basically popup gets tied to a GeoPoint, if user zooms, popup's position gets adjusted automatically.

MapView map = (MapView) findViewById(R.id.mapview);   
MapView.LayoutParams mapParams = new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        <geopoint>,
                        <x offset if required>,
                        <y offset like pinHeight>,
                        MapView.LayoutParams.BOTTOM_CENTER);
map.addView(popUp, mapParams);
Kiran
+1  A: 

(Due to my small reputation I have to add my comment as answer)

Hey Kiran, pls tell us, where u place this code

Hey fhucho, have u found a solution now? Pls post it.

OneWorld
Not ideal solution (that I am using) is to have the popup inside the root RelativeLayout above the map and change its position when user scrolls the map. It's not ideal, because the popup is not moving at the same speed as the map - it's lagging a bit behind the map, when I move the map. When I have time I'll try to manually draw the popup layout in custom overlay.
fhucho
Is that Kiran's solution u are using?
OneWorld
Your solution really sounds just like a work around. I also thought of creating a secondary marker right above the first marker. But the more I think about it, I recognize that its not really good to do it that way. By the way, we are talking about the same issue here: http://stackoverflow.com/questions/3880623/how-to-show-a-balloon-above-a-marker-in-a-mapactivity-is-there-an-api-to-do-that We can merge our questions some time
OneWorld