如何在使用Java的AndroidX中解决Mapbox 9.5.0的未解决导入问题

huangapple go评论67阅读模式
英文:

How to fix unresolved imports for Mapbox 9.5.0 in AndroidX using Java

问题

我正在创建一个Android导航应用程序,使用Mapbox SDK(目前版本为9.5.0),我已成功初始化了地图视图,并能够跟踪用户的当前位置。到目前为止,我没有遇到未解析的导入语句或任何实际问题。我目前正在开发的功能是允许用户在地图上选择位置点,这将在该点上放置一个地图标记并返回标记的坐标。为了实现这个功能,我一直在按照Mapbox文档,特别是这个教程

现在我已经将这段新代码添加到我的应用程序中,我发现了一些问题,有相当多的对象我正试图使用,但无法解决,为了解决这个问题,我查看了我的Java文件顶部的导入语句,发现了一些导入语句无法正常工作,具体来说包括:

import com.mapbox.api.geocoding.v5.GeocodingCriteria;
import com.mapbox.api.geocoding.v5.MapboxGeocoding;
import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.api.geocoding.v5.models.GeocodingResponse;

上述导入中的所有内容在“api”下都有一条红线,并显示错误:“无法解析符号 'api'”。其他一些错误的导入包括:

import com.mapbox.core.exceptions.ServicesException;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import timber.log.Timber;

我不确定为什么所有这些特定的导入无法解析,因为我所有其他的Mapbox导入都没有给我带来任何问题。我怀疑可能是Gradle文件中缺少依赖项或实现,但我已经按照文档指南尽力去做了,所以除非我漏掉了什么重要的东西,否则我不确定原因可能是什么。以下是我在Gradle文件中添加的Mapbox依赖和实现:
项目级别的 build.gradle:

maven {
            url 'https://api.mapbox.com/downloads/v2/releases/maven'
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                username = 'mapbox'
                password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: "my secret password"
            }
        }

以及在我的应用级别 build.gradle 中:

    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0'

如果有人知道我的问题可能是什么,我会非常感谢任何帮助。

英文:

I am in the process of creating an Android navigation application using the Mapbox SDK (version 9.5.0 currently) and I have successfully been able to initialize a map view as well as track the user's current location. Up until this point I have had no issues with unresolved import statements or any real problems. The feature I am currently working on is to allow the user to select a location point on the map, which will place a map marker on that point and return the coordinates of the marker. To incorporate this feature I have been following the Mapbox Documentation, specifically this tutorial.

Now that I have added this new code to my application I have found a few issues, there are quite a number of objects that I am trying to make use of that can not be resolved, to look into this issue I went to my import statements at the top of my java file and found a few imports that are not working properly, namely:

import com.mapbox.api.geocoding.v5.GeocodingCriteria;
import com.mapbox.api.geocoding.v5.MapboxGeocoding;
import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.api.geocoding.v5.models.GeocodingResponse;

The above imports all have a red line under "api" and give the error: " Cannot resolve symbol 'api' " . Some other erroneous imports are:

import com.mapbox.core.exceptions.ServicesException;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import timber.log.Timber;

I am not sure why all of these specific imports are unresolved, as all of my other Mapbox imports haven't given me any issues yet. I suspect it might be a missing dependency or implementation in my Gradle files, but I have followed the documentation guide to be best of my ability so unless I missed something vital I am not sure what the cause might be. Here are the Mapbox dependencies and implementations that I added to my grade files:
Project-level build.gradle:

maven {
            url 'https://api.mapbox.com/downloads/v2/releases/maven'
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                username = 'mapbox'
                password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: "my secret password"
            }
        }

and in my app-level build.gradle:

    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0'

If anyone has an idea of what my issue could be, I would greatly appreciate any help.

答案1

得分: 1

Stick with Maps SDK 9.5.0

Not needed because you can just use regular logging (e.g. log.e rather than Timber.e), but Timber can be downloaded via: https://github.com/JakeWharton/timber#download

https://docs.mapbox.com/android/maps/examples/location-picker 使用 MapboxGeocoding,这是 Mapbox Java SDK 对 Mapbox Geocoding API 的封装。您需要安装 services 模块才能使用 MapboxGeocodinghttps://docs.mapbox.com/android/java/overview/#installationhttps://docs.mapbox.com/android/java/overview/#available-packages。这应该解决以下导入:

import com.mapbox.api.geocoding.v5.GeocodingCriteria;
import com.mapbox.api.geocoding.v5.MapboxGeocoding;
import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.api.geocoding.v5.models.GeocodingResponse;

以及

import com.mapbox.core.exceptions.ServicesException;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

请注意,还有 Places 插件 https://docs.mapbox.com/android/plugins/overview/places/,其中包含一个地点选择功能(https://docs.mapbox.com/android/plugins/examples/place-picker/),比 https://docs.mapbox.com/android/maps/examples/location-picker 更加精细。

英文:

Stick with Maps SDK 9.5.0

Not needed because you can just use regular logging (e.g. log.e rather than Timber.e), but Timber can be downloaded via: https://github.com/JakeWharton/timber#download

https://docs.mapbox.com/android/maps/examples/location-picker uses MapboxGeocoding, which is the Mapbox Java SDK's wrapper around the Mapbox Geocoding API. You need to install the services module to use MapboxGeocoding: https://docs.mapbox.com/android/java/overview/#installation & https://docs.mapbox.com/android/java/overview/#available-packages. This should resolve the

import com.mapbox.api.geocoding.v5.GeocodingCriteria;
import com.mapbox.api.geocoding.v5.MapboxGeocoding;
import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.api.geocoding.v5.models.GeocodingResponse;

and

import com.mapbox.core.exceptions.ServicesException;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

Heads up that there's also the Places Plugin https://docs.mapbox.com/android/plugins/overview/places/, which has a place picker functionality (https://docs.mapbox.com/android/plugins/examples/place-picker/) that's more polished than https://docs.mapbox.com/android/maps/examples/location-picker

答案2

得分: -1

MAPBOX_DOWNLOADS_TOKEN="将你的秘密令牌粘贴在这里",而不是MAPBOX_DOWNLOADS_TOKEN=PASTE_YOUR_SECRET_TOKEN_HERE。

只需尝试这样做,在我的情况下,引号是问题所在。只需删除引号,它就会起作用。

英文:
MAPBOX_DOWNLOADS_TOKEN="PASTE_YOUR_SECRET_TOKEN_HERE" instead of MAPBOX_DOWNLOADS_TOKEN=PASTE_YOUR_SECRET_TOKEN_HERE.

Just try this, in my case the quotes was the problem .Just removed quotes and it worked

huangapple
  • 本文由 发表于 2020年10月9日 16:25:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/64276452.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定