Show popup above map marker in MapView

后端 未结 2 1880
失恋的感觉
失恋的感觉 2020-11-30 21:50

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 smila

相关标签:
2条回答
  • 2020-11-30 21:59

    Here is the "the missing Widget"...

    • Balloons without icons: https://github.com/jgilfelt/android-mapviewballoons#readme

    • Balloons with icons (extends Jeff Gilfelt's project): https://github.com/galex/android-mapviewballoons

    0 讨论(0)
  • 2020-11-30 22:19

    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);
    
    0 讨论(0)
提交回复
热议问题