質問

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

役に立ちましたか?

解決

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

他のヒント

I suppose that you have unique data for every marker on your map.

When you fetch markers data from internet or locally, you should save them into HashMap.

HashMap<Marker, String> map=new HashMap<Marker, String>();
for(MarkerInfo t : fetchedMarkerArray){
    /* add your markers to map, and everything what you need*/
}

When you need to access to data you can easily do that by ( like Daan said you should implement OnMarkerClickListener):

onMarkerClick(Marker marker){
    MarkerInfo m = (MarkerInfo)map.get(marker);
    //show your fragment with data
}

If you have any additional questions, feel free to ask.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top