Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

android - Show popup above map marker in MapView

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...