android 无法在GoogleMap实用程序中使用BubbleIconFactory

kninwzqo  于 2022-12-16  发布在  Android
关注(0)|答案(2)|浏览(131)

无法使用新的BubbleIconFactory,已弃用
依赖关系Gradle构建文件:

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

// want to use this 
BubbleIconFactory bubbleIconFactory = new BubbleIconFactory(this);
5lwkijsr

5lwkijsr1#

BubbleIconFactory已弃用。您可以改用IconGenerator

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您可以找到官方演示活动。

lb3vh1jj

lb3vh1jj2#

BubbleIconFactory在Java中被弃用。是的,正如@antonio提到的,使用IconGenerator
依赖关系:implementation 'com.google.maps.android:android-maps-utils:0.5'
在 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);

在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)

相关问题