在Android版Mapbox SDK中,有没有一种简单的方法可以跳转到当前位置? [英] Is there a simple method to jump to current location in Mapbox SDK for Android?

查看:182
本文介绍了在Android版Mapbox SDK中,有没有一种简单的方法可以跳转到当前位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用最新的Android版Mapbox Maps SDK(v9.5.0)开发一个应用程序.

I am trying to develop an applicition with the latest Mapbox Maps SDK for Android (v9.5.0).

目前,我的地图可以使用 LocationComponent 显示设备的位置,但是UI中没有任何按钮可以返回到设备的位置并将其放置在中心,例如Google Maps使用我的位置按钮".

At the moment, my map can show the location of my device with LocationComponent but there isn't any button in the UI to go back to the device's location and put it in the center, like Google Maps does with the "my location button".

因此,我的问题将是:SDK中是否包含尚未发现的方法,或者我应该结合使用 animateCamera() CameraUpdate()>为此目的?

Therefore my question would be: is there any already included method within SDK which I haven't found or I should use a combination of animateCamera() and CameraUpdate() for this purpose?

推荐答案

最简单的方法是将 animateCamera() CameraUpdate()与最后已知的位置坐标一起使用.要获取最近的已知坐标:

Easiest way would to use animateCamera() and CameraUpdate() with the last known location coordinates. To get the last known coordinates:

if (mapboxMap.getLocationComponent().getLastKnownLocation() != null) {
        Location lastKnownLocation = mapboxMap.getLocationComponent().getLastKnownLocation();
        double lat = lastKnownLocation.getLatitude();
        double longitude = lastKnownLocation.getLongitude();
      }

还有各种相机模式https://docs.mapbox.com/android/maps/examples/location-component-camera-options.摄像机移动后,您可以将模式更改为 CameraMode.TRACKING .但这不同于仅将摄像头移回设备位置而没有任何跟踪行为,这与上面的代码段所示不同.

There are various camera modes as well https://docs.mapbox.com/android/maps/examples/location-component-camera-options. Once the camera is moved, you could change the mode to CameraMode.TRACKING. But this is different than just having the camera move back to the device location without any tracking behavior, as seen in the code snippet above.

这篇关于在Android版Mapbox SDK中,有没有一种简单的方法可以跳转到当前位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆