You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mapbox Android 7.1.1版本部分API弃用无替代方案咨询

Fixing Deprecated Mapbox Marker & Clear Methods (v7.1.1)

Hey there! I’ve dealt with this exact Mapbox migration hurdle in v7.1.1, so let’s walk through how to replace those old marker APIs using the Annotation Plugin you already added.

Replacing addMarker, MarkerOptions, and IconFactory

The old marker-related classes got replaced by the SymbolManager and SymbolOptions from the Annotation Plugin. Here’s how to refactor your code step by step:

First, set up the SymbolManager

You need to initialize this manager after your MapboxMap is ready (usually inside the onMapReady callback):

// Assuming you have references to your MapView and MapboxMap
val symbolManager = SymbolManager(mapView, mapboxMap)
// Tweak these settings if you want markers to overlap or ignore map labels
symbolManager.iconAllowOverlap = true
symbolManager.iconIgnorePlacement = true

Then create and add your marker

Replace your old addMarker line with this code:

// Use the SymbolManager's built-in icon factory to load your drawable
val markerIcon = symbolManager.iconFactory.fromResource(R.drawable.ic_marker)

// Build your marker (this replaces MarkerOptions)
val markerSymbol = SymbolOptions()
    .withLatLng(LatLng(lat, lng))
    .withIcon(markerIcon)
    .withIconSize(1.0f) // Adjust this number to make the marker bigger/smaller

// Add the marker to the map
symbolManager.create(markerSymbol)

Replacing mapboxMap.clear()

The old clear() method was deprecated because it wipes everything on the map (including layers you might want to keep). Instead, use the SymbolManager to only remove the markers you added:

// Delete all markers managed by this SymbolManager
symbolManager.deleteAll()

If you need to clear other map elements (like custom layers), you’ll have to target them individually, but for markers from the Annotation Plugin, deleteAll() is the perfect replacement.

Quick Tips

  • Make sure you initialize the SymbolManager after the MapboxMap is fully loaded (don’t try to set it up before onMapReady fires).
  • If you need to manage different groups of markers, you can create separate SymbolManager instances or use data source filters to organize them.

内容的提问来源于stack exchange,提问作者Radesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:29:39