android-studio - 在具有功能的android studio中使用mapbox
问题描述
我在 android studio 中使用 MapBox 并在地图中显示一个点。现在我想要一个函数来获取一个 LatLng 变量作为输入并在地图上显示该点。(我想要在 onMapReady 之外有一个函数,通过调用该函数,将点作为输入发送给该函数在函数内,点会出现在地图上。)。请指导我
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, YOUR_MAPBOX_ACCESS_TOKEN);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS, 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
}
});
}
});
解决方案
很简单。在方法中编写以下代码onMapReady
并使用此mapboxMap
变量在地图上添加标记点。
LatLng latLng = new LatLng(20.5992, 72.9342);
mapboxMap.addMarker(new MarkerOptions().position(latLng).setTitle("set title of marker point"))
推荐阅读
- spring-boot - Spring boot r2dbc transactional:注释哪个方法
- java - 在 docker 容器上托管 JavaFX 项目
- meteor - 如何将 bootstrap 5 javascript 插件导入 Meteor-Svelte 项目
- css - 我可以选择 CSS 网格中的最后一列吗?
- ios - 如何在 React 本机 ios 上设置按钮不可点击
- asp.net-core - asp.net core中登录过期时的注销处理设置
- git - 在不发布的情况下激活 ADF 触发器
- reactjs - 如何禁用和灰显 ReactSelect 组件
- java - 如何从在java中返回地图的流中收集地图
- javascript - 跟随滚动但返回其主页的浮动按钮(HTML、C#.NET)