Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library blocks the ui when making a task from its data #326

Open
alicansekban opened this issue Mar 17, 2023 · 1 comment
Open

Library blocks the ui when making a task from its data #326

alicansekban opened this issue Mar 17, 2023 · 1 comment

Comments

@alicansekban
Copy link

alicansekban commented Mar 17, 2023

So what am trying to do here is, i take 3 routes from the map when user chooses a location to go, from these routes i take all the pins
and compare them with my pin list(i take it from our backend) for calculating toll price. But when i try to do this on background with another thread using coroutine, library wouldnt allow me to do and gives a crash or when i try to do it foreground it freezes the ui of course.

What am i suppose to do here ?

this is my method for comparing lists and posting them on our api.

private fun calculateTollPrice(routes: List) {

    val highwayTollList = retrieveDataModelSharedPref(
        "PIN_TOLL_LIST",
        PinTollListResponse::class.java
    )
    val vehicleType = SPUtils.getInstance().getInt(SPPARAM.VEHICLE_TYPE)
    var tmpTollPointLoc: Point
    routes.forEachIndexed { index, drivingRoute ->
        if (drivingRoute.metadata.flags.hasTolls) {
            drivingRoute.geometry.points.forEach { point ->
                tollList.addAll(highwayTollList?.items?.filter { tollItem ->
                    tmpTollPointLoc = Point(tollItem.latitude, tollItem.longitude)
                    val distance = Geo.distance(tmpTollPointLoc, point)
                    distance < tollItem.radius
                } ?: emptyList()
                )
            }
            viewModel.calculateTollPrice(
                CalculateTollPriceRequest(
                    tollList.distinctBy { it.id },
                    index,
                    tollList.count(),
                    vehicleType
                )
            )
            tollList.clear()
        }

    }
}
@YandexMapKit
Copy link
Collaborator

Can you specify more precisely which line leads to a crash?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants