Encoded polyline invalid using DirectionsRoute.geometry() using Mapbox

问题描述 投票:0回答:0

我目前正在使用 Android Studio 使用 Mapbox 进行开发。我正在尝试获取覆盖所选路线的静态图像。我使用 DirectionsRoute.geometry() 来获取我的编码折线,但它似乎无效。当我尝试使用 mapbox API 获取静态图像时,总是出现类似“{"message":"Not Authorized - No Token"}" 或 "{"message":"Overlay bounds are out of range 的错误。 “}”

但是如果我给它一个有效的编码折线,Mapbox API 会给我一个图像,所以我确定问题出在我的折线上,在这种情况下是 route.geometry()。

这条路线也是一个有效的 DirectionsRoute 对象。这是我的代码:

                    val baseUrl = "https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/"
                    val staticMapUrlBuilder = StringBuilder()
                    staticMapUrlBuilder.append(baseUrl)
                    staticMapUrlBuilder.append("path-5+f44-0.5(")
                    staticMapUrlBuilder.append(route.geometry())
                    staticMapUrlBuilder.append(")/auto/500x300?access_token=")
                    staticMapUrlBuilder.append(apiKey)
                    val url2 = staticMapUrlBuilder.toString()


                    println(route.geometry())

                    // Use an image loading library to load the static image into an ImageView
                    Glide.with(this)
                        .load(url2)
                        .into(record)

这是我在终端中打印的一些无效折线,我从 route.geometry() 中得到这些折线:

这个错误是:{"message":"Overlay bounds are out of range."}

ckakfAh%7BlzgFlKp@fEX~@eS

这个错误是:{"message":"Not Authorized - No Token"}

uoujfAjvmzgFoACh%5Cd@sIfKiO%60UeBpAgBd@oBNuBFqJG%7DLEqA?uA?y%5CAsD?_D?cLAiGAqF?%7BRHiU@aECqLOkOCcVOgXCuFBgLBwP?yGEk@AaDM%7BEQyCOaAGgCMiCEkEP%7DCMsKa@gBGw@%7BHkAcKiAaJqBcPeAXIBsKlBCaB%5CkCf@kC?q@?_@fEX~@eS

我也试过在美国打印一条很短的路线,但这显然不是我的路线: enter image description here 这是我预期的路线: enter image description here

我的代码有什么问题,我是否正确使用了几何图形?谁能帮我?非常感谢!

我试图从 DirectionsRoute.geometry() 获取编码的折线,我可以获得一个字符串,但这个字符串似乎无效,我希望有一个有效的编码折线字符串,它可以帮助我在静态图像中显示我的路线通过使用Mapbox API.

google-maps mapbox mapbox-android google-polyline mapbox-api-directions
© www.soinside.com 2019 - 2024. All rights reserved.