lena
lena

Reputation: 67

Info Window on shapes(circle, polygon) in Android Maps App

I have an android app which one of its screens uses google maps, and I load some regions on it. I want to be able to click on a region/shape(circle or polygon) and an info window to appear. I am searching but I cant find enough information on how to show info windows on shapes, only on markers. Is that not a common practice? What should I do? Could anyone help, even theoretically? Any help or direction would be appreciated, thank you very much!

Upvotes: 2

Views: 834

Answers (1)

Somguy
Somguy

Reputation: 31

  1. Create a customCircleOnClickListener (or don't and use the title and snippet properties, as I am doing in step 3).

  2. Then add:

    mMap.setInfoWindowAdapter(new
    CustomInfoWindowAdapter(MainActivity.this));
    mMap.setOnCircleClickListener(customCircleOnClickListener());
    
  3. Finally:

    public GoogleMap.OnCircleClickListener customCircleOnClickListener() {
        return new GoogleMap.OnCircleClickListener() {
            @Override
            public void onCircleClick(Circle circle) {
                Log.d("MainActivity", "Clicked a ball!");
    
                POIAnnotationCircle annotCircle = annotationsByCircle.get(circle);
                markerForInfoWindow = mMap.addMarker(new MarkerOptions()
                        .alpha(0.0f)
                        .infoWindowAnchor(.6f,1.0f)
                        .position(annotCircle.getCoordinate())
                        .title(annotCircle.getTitle())
                        .snippet(annotCircle.getSnippet()));
    
                markerForInfoWindow.showInfoWindow();
            }
        };
    }
    

Upvotes: 3

Related Questions