首页 > 解决方案 > Kotlin:将 URL 转换为位图时的毕加索问题

问题描述

在此处输入图像描述

在这段代码中有“java.lang.IllegalStateException:方法调用不应该从主线程发生。” 问题

如何解决这个问题

user_URL[i] 值为(URL:字符串)

代码是:

    user_URL = maprepo.returnImage()
    latitude = maprepo.returnLatitude()
    longitude = maprepo.returnLongitude()

    for (i in 0 until latitude.size step (1)) {

        var bitmap: Bitmap =Picasso.with(context).load(user_URL[i]).get()

        val makerOptions = MarkerOptions()
        makerOptions
            .position(LatLng(latitude[i], longitude[i]))
            .title("")
            .icon(BitmapDescriptorFactory.fromBitmap(bitmap))

        googleMap.addMarker(makerOptions)

    }

标签: androidgoogle-mapskotlinbitmappicasso

解决方案


推荐阅读