gpt4 book ai didi

java - Android Studio 中的 Mapbox 黑屏

转载 作者:行者123 更新时间:2023-12-02 08:47:47 25 4
gpt4 key购买 nike

我正在尝试使用 Mapbox 在 android studio 中制作一个 map 应用程序,它曾经可以工作,但现在只显示空白屏幕。

多年来我一直在摆弄它,试图让它工作,但没有成功。我还有一个“未找到兼容并排 NDK 版本”的问题。默认是 20.0.5594570' 错误/警告我也不明白。任何帮助将不胜感激,TIA。

MainActivity.java:

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {

private MapView mapView;
private MapboxMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Mapbox.getInstance(this, getString(R.string.access_token));
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);

}

@SuppressWarnings("deprecation")
public void onMapReady(@NonNull MapboxMap mapboxMap) {
map = mapboxMap;
mapboxMap.setStyle(Style.OUTDOORS);

mapboxMap.setCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(53.472, -2.239))
.zoom(8.0)
.build());

mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(53.472, -2.239))
.title("John Dalton"));
}

@Override
public void onStart() {
super.onStart();
mapView.onStart();
}

@Override
public void onResume() {
super.onResume();
mapView.onResume();
}

其余代码只是 onStop() 函数等。

build.gradle(:应用程序):


android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.example.stationmapper"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//Mapbox dependencies
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.0.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.8.0'
}

我认为这足以确定问题范围并解决问题,但如果需要其他任何内容,我将编辑并提供它。

最佳答案

您的 Activity 实现了 OnMapReadyCallback,但在 mapView.onCreate(savedInstanceState); 之后缺少 mapView.getMapAsync(this)

@Override public void onMapReady(@NonNull MapboxMap mapboxMap) {
map = mapboxMap;
mapboxMap.setStyle(Style.OUTDOORS, new Style.OnStyleLoaded() {
@Override public void onStyleLoaded(@NonNull Style style) {

// Map is set up and the style has loaded. Now you can add data or make other map adjustments.

}
});
}

然后,在 onStyleLoaded() 回调区域中添加标记。

不要使用已弃用的 addMarker(),请考虑使用 Mapbox 的注释插件 https://docs.mapbox.com/android/plugins/overview/annotationSymbolLayer 和来源 https://docs.mapbox.com/android/maps/overview/annotations/#source-and-layer

关于java - Android Studio 中的 Mapbox 黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60971445/

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