简体   繁体   中英

Custom Markers in Google Maps

I have built a music app and now I am trying to build a mapping feature more like Shazam's or Instagrams as follows:

地图显示内容堆叠在一起

Where initially, I am to drop a general marker on several points without actually showing all the activity in that location. Then on tapping that marker, the map will zoom in and other markers that are more specific will show, and so on..

地图显示了更详细的标记

Is there a tutorial available that I can follow the to achieve this effect in Android?

I have just found out that Google has a utility library that provides for marker clustering. The documentation can be found here https://developers.google.com/maps/documentation/android-api/utility/marker-clustering

You can create a method to add custom markers using this function:

private void drawCustomMarker(LatLng point) {
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(point);
    markerOptions.title("SMS");
    markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.sms));
    mMap.addMarker(markerOptions);
}

You can pass LatLng object where you want to drop the marker. I have used it in map click listener:

mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
    @Override
    public void onMapLongClick(LatLng newlatLng) {
        drawCustomMarker(newlatLng);
    }
});

Hope it will help you..!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM