gpt4 book ai didi

java - Android 版 Tomtom map sdk 无法加载图 block

转载 作者:行者123 更新时间:2023-12-02 09:32:54 26 4
gpt4 key购买 nike

我尝试将 TomTom map 添加到使用 Kotlin 构建的 Android 应用程序中,但出现错误 Tomtom Maps SDK for android failed加载图 block 并显示一个空 map ,如下图所示:

tomtom maps failed to load tiles

这是我正在使用的文件和详细配置:

  • 在项目级别 Gradle 文件中,我有:
    allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.tomtom.com:8443/nexus/content/repositories/releases/"
}
}
}

  • 在应用程序级别 Gradle 文件中,我有:

dependencies {
implementation("com.tomtom.online:sdk-maps:2.4244")
}

  • 我已将 APK 添加到 AndroidManifests 文件中:
    <meta-data
android:name="OnlineMaps.Key"
android:value="<my-Key-here>" />
  • 此外, map fragment 也会添加到 .XML 文件中:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapActivity">

<fragment
android:id="@+id/mapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.tomtom.online.sdk.map.MapFragment"
/>


</androidx.constraintlayout.widget.ConstraintLayout>
  • 最后,这是用于启动 map 的 Kotlin 代码:

//lateinit late initialization of non-null type variables
private lateinit var map: TomtomMap
private lateinit var fusedLocationClient: FusedLocationProviderClient
private lateinit var lastLocation: Location

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map)
val mapFragment = supportFragmentManager
.findFragmentById(R.id.mapFragment) as MapFragment
mapFragment.getAsyncMap(this)
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)

}


companion object {
private const val LOCATION_PERMISSION_REQUEST_CODE = 101
}
private fun setUpMap() {
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION), LOCATION_PERMISSION_REQUEST_CODE)
return
}
map.isMyLocationEnabled = true
fusedLocationClient.lastLocation.addOnSuccessListener(this) {
location ->
if (location != null){
lastLocation = location
val currentLatLng = LatLng(location.latitude, location.longitude)
val balloon = SimpleMarkerBalloon("You are Here")
map.addMarker(MarkerBuilder(currentLatLng).markerBalloon(balloon))
map.centerOn(CameraPosition.builder(currentLatLng).zoom(7.0).build())

}

}
}


override fun onMapReady(@NonNull tomtomMap: TomtomMap) {
this.map = tomtomMap
setUpMap()
}

最佳答案

有两个可能需要检查的点:

关于java - Android 版 Tomtom map sdk 无法加载图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57805452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com