[英]Tomtom Maps sdk for android failed to load tile
I'm trying to add TomTom
maps to my android application that is built with Kotlin
, but it gives me the error Tomtom Maps SDK for android failed to load tile
and shows an empty map as shown in the image below : 我正在尝试将
TomTom
地图添加到使用Kotlin
构建的android应用程序中,但它给我的错误是Tomtom Maps SDK for android failed to load tile
并显示了一个空地图,如下图所示:
And here are my files and detailed configurations I'm using: 这是我正在使用的文件和详细配置:
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.tomtom.com:8443/nexus/content/repositories/releases/"
}
}
}
dependencies {
implementation("com.tomtom.online:sdk-maps:2.4244")
}
APK
to the AndroidManifests
file : APK
添加到AndroidManifests
文件中: <meta-data
android:name="OnlineMaps.Key"
android:value="<my-Key-here>" />
<?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>
//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()
}
Two possible points to check: 检查两个可能的点:
Your API key is not valid. 您的API密钥无效。 Please check your API key by calling a raw TomTom Maps endpoint: 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 and check again.
请通过调用原始的TomTom Maps端点来检查API密钥: https : //api.tomtom.com/map/1/tile/basic/main/0/0/0.png? key =your_api_key ,如果不能要查看地图图块图像-通过转到TomTom开发人员门户注册新的API密钥,然后再次检查。
Your API key is placed in the wrong place inside AndroidManifest.xml file. 您的API密钥放置在AndroidManifest.xml文件内的错误位置。 Make sure that it's placed inside the
<application>
tag, next to <activity>
tag. 确保将其放在
<activity>
标记旁边的<application>
标记内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.