使用以下代码将各种行添加到表示路径的地图中:
private LineLayer makeLineLayer(List<GeoPoint> routePoints, String title) {
String sourceTitle = "line-layer-" + lineCount;
List<Position> points = new ArrayList<>(routePoints.size());
List<Feature> routes = new ArrayList<>(routePoints.size());
for (GeoPoint point : routePoints) {
points.add(Position.fromCoordinates(point.getLongitude(), point.getLatitude()));
}
LineString route = LineString.fromCoordinates(points);
Feature routeFeature = Feature.fromGeometry(route);
routeFeature.addStringProperty("custom-line", "0");
routes.add(routeFeature);
GeoJsonSource linesSource = new GeoJsonSource(
sourceTitle,
FeatureCollection.fromFeatures(routes));
mapboxMap.addSource(linesSource);
LineLayer lineLayer = new LineLayer(title, sourceTitle);
lineLayer.setProperties(
//Sets properties...
);
return lineLayer;
}
LineLayer lineLayer = makeLineLayer(getRoutePoints());
mapboxMap.addLayer(lineLayer);
Run Code Online (Sandbox Code Playgroud)
我希望能够确定何时单击其中一行.目前,MapBox调用OnMapClick并传入一个LatLng对象.然后,我可以custom-line使用以下内容查询属性的渲染功能:
PointF pixel = …Run Code Online (Sandbox Code Playgroud) 我正在研究当前Android应用程序中优秀的Mapbox库.
我试图整合这个问题时遇到过这个问题PlacePickerActivity.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.hide()' on a null object reference
at com.mapbox.mapboxsdk.plugins.places.picker.ui.PlacePickerActivity.onCreate(PlacePickerActivity.java:65)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
Run Code Online (Sandbox Code Playgroud)
我的应用程序风格如下: -
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
我使用的版本是: -
// MAPBOX
implementation "com.mapbox.mapboxsdk:mapbox-android-sdk:$mapBoxSdkVersion"
implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-traffic:$mapBoxTrafficVersion"
implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-places:$mapBoxPlacesVersion"
mapBoxSdkVersion = "6.8.1"
mapBoxTrafficVersion = "0.6.0"
mapBoxPlacesVersion = "0.6.0"
Run Code Online (Sandbox Code Playgroud)
我配置我的工具栏如下: -
/**
* @param toolbar
*/
private void manageToolbar(final Toolbar toolbar) {
mToolbar …Run Code Online (Sandbox Code Playgroud) 我正在尝试从已添加到“资产”文件夹的 GeoJSON 文件中向地图添加标记。
我试图遵循文档但是无法获得预期的结果,因为在运行应用程序时找不到标记。
我的尝试:
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS,
new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
enableLocationComponent(style);
GeoJsonSource source = null;
try {
source = new GeoJsonSource("geojson-source", new URI("asset://markerdata.geojson"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
style.addSource(source);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
style.addImage("marker", icon);
SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); // ?
symbolLayer.setProperties(PropertyFactory.iconImage("marker"));
style.addLayer(symbolLayer);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我注意到SymbolLayer期望 alayer-id并且source-id无法理解这些是什么。
我正在尝试使用适用于 Android v10 的新地图框,特别是新的 3D 地形功能。所有示例都在 Kotlin 中,我已按照下面的在线指南进行操作,但我不断遇到相同的错误消息。
网上例子:
mapboxMap.loadStyle(
styleExtension = style(Style.SATELLITE_STREETS) {
+rasterDemSource("TERRAIN_SOURCE") {
url("mapbox://mapbox.mapbox-terrain-dem-v1")
}
+terrain("TERRAIN_SOURCE") {
exaggeration(1.1)
}
)
Run Code Online (Sandbox Code Playgroud)
以下是我正在使用的代码:
public class MainActivity extends AppCompatActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
//mapView.getMapboxMap().loadStyleUri(Style.OUTDOORS);
MapboxMap mapboxMap = mapView.getMapboxMap();
StyleContract.StyleExtension styleExtension = new StyleContract.StyleExtension() {
@NonNull
@Override
public String getStyleUri() {
return Style.SATELLITE;
}
@NonNull
@Override
public List<StyleContract.StyleSourceExtension> getSources() {
RasterDemSource rasterDemSource = new RasterDemSource(new RasterDemSource.Builder("TERRAIN_SOURCE"));
rasterDemSource.url("mapbox://mapbox.mapbox-terrain-v2");
List<StyleContract.StyleSourceExtension> ex = …Run Code Online (Sandbox Code Playgroud) 当我在应用程序中使用MAPBOX时,我不知道如何获取当前经纬度和经度。我使用这种方式获取当前位置,但其显示空对象引用,请帮助我解决问题
mapView = (MapView)view. findViewById(R.id.mapView);
mapView.setStyleUrl(Style.MAPBOX_STREETS);
mapView.onCreate(savedInstanceState);
//Add a mapBoxMap
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
mapboxMap.setMyLocationEnabled(true);
// Set the origin waypoint to the devices location
Position origin = Position.fromCoordinates(mapboxMap.getMyLocation().getLongitude(), mapboxMap.getMyLocation().getLatitude());
Log.i("RR","mapboxMap.getMyLocation();"+origin);
// Log.i("RR","mapboxMap.getMyLocation();"+mapboxMap.getMyLocation().getLongitude());
mapboxMap.getUiSettings().setZoomControlsEnabled(true);
mapboxMap.getUiSettings().setZoomGesturesEnabled(true);
mapboxMap.getUiSettings().setScrollGesturesEnabled(true);
mapboxMap.getUiSettings().setAllGesturesEnabled(true);
}
});
Run Code Online (Sandbox Code Playgroud) 是否可以使用自定义 OSRM 服务器 (Docker)在导航 SDK 中进行路由?如果我在postgrey db 中有自定义街道,我如何计算这条街道上的路线?
某事如
NavigationRoute.builder(this)
.baseUrl("my server url")
Run Code Online (Sandbox Code Playgroud)
确实向我的服务器发出请求,但在查询中附加了我不想要的参数:
/route/v1/driving/directions/v5/mapbox/driving-traffic/
Run Code Online (Sandbox Code Playgroud)
我只需要
/route/v1/driving/
Run Code Online (Sandbox Code Playgroud)
是否可能或存在一些将 osrm 格式转换为 mapbox 格式的库?
GeoJson 功能如下所示:
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
43.59375,
59.17592824927136
]
}
}
Run Code Online (Sandbox Code Playgroud)
在Mapbox使用 Java/JVM 时,我们可以构建这样的特性:
val testFeature = Feature.fromGeometry(Point.fromLngLat(2.0,3.0))
Run Code Online (Sandbox Code Playgroud)
但我似乎没有找到从特征中获取坐标/点的方法。
有一个Feature#getGeometry()但我无法从中获取坐标,因为这只是 GeoJson 界面本身的一个糖。
我已将 geoJson 源加载到我的 mapView 中。我的 .net 中有一个搜索栏activity。所以我的计划是,我想使用添加到地图的源searchBar中的要素类型来填充我的建议。geoJson我想从onMapStyleLoaded方法中做到这一点。
那么,有没有一种方法可以获取所有geoJson属性(例如“名称”)的详细信息,并将所有属性添加到arrayList加载地图时?
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
SearchActivity.this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
mapboxMap.addOnMapClickListener(SearchActivity.this);
addGeoJsonSourceToMap(style);
// Create FillLayer with GeoJSON source and add the FillLayer to the map
style.addLayer(new FillLayer(geoJsonLayerId, geoJsonSourceId)
.withProperties(fillOpacity(0.5f)));
GeoJsonSource source = style.getSourceAs(geoJsonSourceId);
if (source != null){
List<Feature> features = source.querySourceFeatures(Expression.get("name"));
//I want to all the features of my geoJson source so I can pass …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,其中我必须根据用户导航旋转箭头。
我正在使用最新的 Mapbox SDK。
我尝试过设置障碍(使用纬度和经度计算)但未能成功。
我不知道如何实现它。
它(箭头标记)应该在预定义的多边形路径上导航。
如何调整 中的徽标和归属com.mapbox.mapboxsdk.maps.MapView?在较旧的 SDK v9 中,可以通过 XML 属性(或通过以编程方式更改 UiSettings)简单地设置 UiSettings。
mapbox:mapbox_uiAttributionMarginBottom="8dp"
mapbox:mapbox_uiAttributionMarginLeft="32dp"
Run Code Online (Sandbox Code Playgroud)
知道如何在 Mapbox SDK v10 上实现相同的效果吗?