android 的 Tomtom Maps sdk 加载图块失败
Tomtom Maps sdk for android failed to load tile
我正在尝试将 TomTom
地图添加到我使用 Kotlin
构建的 android 应用程序,但它给我错误 Tomtom Maps SDK for android failed to load tile
并显示一个空的地图如下图所示:
这是我的文件和我正在使用的详细配置:
- 在项目级别 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>" />
- 此外,地图片段已添加到 .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>
- 最后,这是用于启动地图的 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()
}
两个可能的检查点:
您的 API 密钥无效。请通过调用原始 TomTom 地图端点检查您的 API 密钥:https://api.tomtom.com/map/1/tile/basic/main/0/0/0.png?key=your_api_key and if you are not able to see the map tile image - register your new API key by going to TomTom Developer Portal 并再次检查。
您的 API 密钥在 AndroidManifest.xml 文件中的位置错误。确保它位于 <application>
标签内,<activity>
标签旁边。
我正在尝试将 TomTom
地图添加到我使用 Kotlin
构建的 android 应用程序,但它给我错误 Tomtom Maps SDK for android failed to load tile
并显示一个空的地图如下图所示:
这是我的文件和我正在使用的详细配置:
- 在项目级别 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>" />
- 此外,地图片段已添加到 .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>
- 最后,这是用于启动地图的 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()
}
两个可能的检查点:
您的 API 密钥无效。请通过调用原始 TomTom 地图端点检查您的 API 密钥:https://api.tomtom.com/map/1/tile/basic/main/0/0/0.png?key=your_api_key and if you are not able to see the map tile image - register your new API key by going to TomTom Developer Portal 并再次检查。
您的 API 密钥在 AndroidManifest.xml 文件中的位置错误。确保它位于
<application>
标签内,<activity>
标签旁边。