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
243 views
in Technique[技术] by (71.8m points)

android - mapView show overlay details when clicked

Ive been trying to acheive the same, this is exactly what i want :- Google Maps Image

i have implemented googleMapView with overlays, i have one issue i want to show a popup when clicked on each overlay, and when i click on another overlay the previous popus should disappear and new one should appear at the clicked location(ie projection points). And popup shouldnt appear when i click anywhere else on screen.Im using onTap event to record onclick. (map_overlay) is the layout that i want to show when someone click a projection point on the map. The code is below and map_overlay.xml could be any file.

Class: ItemizedOverlay

public boolean onTap(GeoPoint p, MapView mapView) {

LayoutInflater inflater = (LayoutInflater)cContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LayoutParams lp = new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, p, LayoutParams.WRAP_CONTENT);
LinearLayout view = (LinearLayout)inflater.inflate(R.layout.map_overlay, null);

mapView.removeView(view);    
mapView.invalidate();    
mapView.addView(view,lp);

mapView.invalidate();

return true;
}

Below is the Main class in which im displaying projection points which is working fine and im calling I have implemented the onTap event in another class as shown above:

public **class MapView** extends MapActivity{
    private ArrayList<MyClass> overlayItem ;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.large_mapview);
        mapView = (MapView) findViewById(R.id.mapview);
       // mapView.setBuiltInZoomControls(true);

        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.mappointer2);
        ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable,this);
        OverlayItem overlayitem;
        GeoPoint point;
        double lat;
        double lng;        

        for (int i = 0; i < overlayItem.size(); i++) {

            lat = Double.parseDouble(overlayItem.get(i).getLatitude());
            lng = Double.parseDouble(overlayItem.get(i).getLongitude());
            point = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));

            overlayitem = new OverlayItem(point, i+"".toString(), overlayItem.get(i).getDetails().toString());
            itemizedoverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedoverlay);

        }

        mapView.invalidate();
    }
}
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Check out Android-mapviewballoons on github. Has an ItemizedOverlay that you can extend that does this exact thing. I use it in several of my apps.


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

...