我正在使用MapBox,并在设置用户的地理编码的地方显示了一个图钉。该程序在所有apis...except 19上都能正常工作,因为它是黑屏的。我不知道该怎么理解它,因为我遵循了这里的文档:
https://www.mapbox.com/android-sdk/examples/marker/
下面是我的一些代码:
Gradle:
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.0-beta.1@aar'){
transitive=true
}
compile('com.mapbox.mapboxsdk:mapbox-android-services:1.2.1@aar') {
transitive = true
}
获取mapView
mapView = (MapView) findViewById(R.id.mapView);
mapView.setStyle(Style.MAPBOX_STREETS);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
地图准备就绪后回调:
public void onMapReady(MapboxMap mapboxMap) {
// Relevant sources shown only
mapboxMap.setStyleUrl(Style.MAPBOX_STREETS);
mapboxMap.setOnInfoWindowClickListener(this);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(geocodeLatLng)
.zoom(15)
.bearing(0)
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Marker position = mapboxMap.addMarker(new MarkerOptions().position(geocodeLatLng).title(location));
position.setSnippet(address);
position.showInfoWindow(mapboxMap, mapView);
}
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:style_url="mapbox://styles/mapbox/streets-v9"
mapbox:zoom="11"/>
</RelativeLayout>
我还有什么遗漏的吗?我也有AndroidManifest.xml和gradle的变化。它显然可以在较新的API中工作,而不是在较旧的API中。该网站说他们支持来自API 15+?
发布于 2016-08-15 01:24:55
不知道为什么,但这解决了它。之前我是在我的MapFragmentActivity最顶端这样做的:
MapboxAccountManager.start(this, getString(R.string.access_token));
事实证明(仔细阅读他们的文档)应该在MainActivity.java中的应用程序加载时完成。我这样做了,它起作用了。出于某些原因,如果您在setContentView(R.layout.activity_main);
之前在所讨论的类中执行此操作,但仅在较新的设备上执行此操作(不确定区别),它就会起作用。
https://stackoverflow.com/questions/38927131
复制相似问题