Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use BubbleIconFactory in Google map utils

Unable to use The new BubbleIconFactory its giving deprecated

dependency Gradle build file:

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.4+'
}


// want to use this 
BubbleIconFactory bubbleIconFactory = new BubbleIconFactory(this);
like image 410
witted_coder Avatar asked Dec 14 '22 06:12

witted_coder


2 Answers

BubbleIconFactory is deprecated. You can use IconGenerator instead:

IconGenerator iconFactory = new IconGenerator(this);

MarkerOptions markerOptions = new MarkerOptions()
    .icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Your text here")))
    .position(new LatLng(40, -4))
    .anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());

mMap.addMarker(markerOptions);

Here you can find the official demo activity.

like image 70
antonio Avatar answered Feb 15 '23 03:02

antonio


BubbleIconFactory is deprecated in Java. and yes as @antonio mentioned, use IconGenerator.

Dependency: implementation 'com.google.maps.android:android-maps-utils:0.5'

In Java

    IconGenerator iconGenerator = new IconGenerator(context);
    // You can style icon using the IconGenerator.STYLE_BLUE
    iconGenerator.setStyle(IconGenerator.STYLE_BLUE);

    MarkerOptions markerOptions = new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromBitmap(iconGenerator.makeIcon("Your text here");))
            .position(new LatLng(-33.8523341, 151.2106085))  // Sydney, Australia
            .anchor(iconGenerator.getAnchorU(), iconGenerator.getAnchorV());
    mMap.addMarker(markerOptions);

In Kotlin

   val iconGenerator = IconGenerator(this)
    // You can style icon using the IconGenerator.STYLE_BLUE 
    iconGenerator.setStyle(IconGenerator.STYLE_GREEN)
    
   
    val markerOptions = MarkerOptions()
     
 .icon(BitmapDescriptorFactory.fromBitmap(iconGenerator.makeIcon("Text here")))
        .position(LatLng(-33.8523341, 151.2106085)) // Sydney, Australia
        .anchor(iconGenerator.anchorU, iconGenerator.anchorV)
    mMap.addMarker(markerOptions)
like image 33
Nikunj Patel Avatar answered Feb 15 '23 03:02

Nikunj Patel