可以通过以下步骤实现:
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:10.2.0'
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.plugins.annotation.Circle;
import com.mapbox.mapboxsdk.plugins.annotation.CircleManager;
import com.mapbox.mapboxsdk.plugins.annotation.CircleOptions;
public class MainActivity extends AppCompatActivity {
private MapView mapView;
private CircleManager circleManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, "YOUR_MAPBOX_ACCESS_TOKEN");
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> {
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
circleManager = new CircleManager(mapView, mapboxMap, style);
addCircleMarker(new LatLng(40.7128, -74.0060), 1000); // 添加圆形标记
});
});
}
private void addCircleMarker(LatLng latLng, float radius) {
CircleOptions circleOptions = new CircleOptions()
.withLatLng(latLng)
.withCircleColor(Color.parseColor("#FF0000"))
.withCircleRadius(radius);
circleManager.create(circleOptions);
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
以上代码将在地图上绘制一个圆形的红色标记,位置为纽约市中心(纬度40.7128,经度-74.0060),半径为1000米。
推荐的腾讯云相关产品:腾讯云地图服务(https://cloud.tencent.com/product/maps)
请注意,以上答案仅供参考,具体实现方式可能因项目需求和环境而有所不同。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云