简体   繁体   中英

In mapbox, how do you change your location's annotation icon?

I know I can set the icon of other annotations / markers using:

 new MarkerOptions().icon(myIcon)

My question for you is how do I modify my location marker?

You can use IconFactory :

IconFactory iconFactory = IconFactory.getInstance(<activity context>);
new MarkerOptions().icon(iconFactory.fromResource(<drawable resource>));

Or you can customize bitmap icon while adding icon into Marker by using IconFactory.recreate() method, example scaled bitmap:

Icon icon    = iconFactory.fromResource(<drawable resource>);
Icon newIcon = IconFactory.recreate(icon.getId(), Bitmap.createScaledBitmap(icon.getBitmap(), 35, 35, false));

If you look at the API, in an example, you can use this code

mapView.addMarker(new MarkerOptions()
    .position(new LatLng(41.885, -87.679)));

The marker will be at the specified coordinates

Here is the link for further reference

https://www.mapbox.com/help/first-steps-android-sdk/#drawing-a-marker

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