user3412690 user3412690 - 3 months ago 13
Android Question

Google maps api v2, on marker click to open a fragment on the map

What I want to realise:

I want my markers, that are clickable, to open a fragment on top of the map when I'm in their proximity.
This fragment will list some text and pictures.
I want this fragment to overlay only a part of the googlemap and to be closeable.

I already have some basic info in the 'snippet'-thingy that opens one click.
I also have a function that calculates the distance from the middle of the screen to a location and puts it in the snippet.

some code I have:

simLocatie.setLatitude((googlemap.getCameraPosition().target).latitude);
simLocatie.setLongitude((googlemap.getCameraPosition().target).longitude);

googlemap.addMarker(new MarkerOptions()
.title(een.getName())
.position(new LatLng(een.getLatitude(),een.getLongitude()))
.snippet("distance:"+simLocatie.distance(een))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_monument)));


Thanks in advance!
if I didn't explain myself good enough please ask for more

Answer

implement OnMarkerClickListener

and use this method: (it will be called when u click on a marker)

@Override
    public boolean onMarkerClick(Marker marker) {
        return false;
    }

inside this function open your fragment.

http://developer.android.com/guide/components/fragments.html