问题描述
我知道使用locationListener
并触发GPS的方式是这样的:
I know the way to use locationListener
and triggering the GPS is done like that:
mapboxMap.setMyLocationEnabled(true);
我想在应用启动时打开locationListener
,但是我不想在startActivity
中使用地图.只需使用不带地图的locationListener
.
I want to open the locationListener
at app start, but I don't want to use the map in the startActivity
. Just using the locationListener
without map.
我该如何使用Mapbox?
How can I do with Mapbox ?
推荐答案
您可以使用LocationEngine
的实例来获取位置更新,而无需显示地图.
You can use an instance of LocationEngine
to acquire location updates without showing the map.
final LocationEngine locationEngine = new LostLocationEngine(this);
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.addLocationEngineListener(new LocationEngineListener() {
@Override
public void onConnected() {
locationEngine.requestLocationUpdates();
}
@Override
public void onLocationChanged(Location location) {
}
});
locationEngine.activate();
请确保一旦完成获取所需的位置信息或您的活动被破坏后,您将删除所有侦听器,停止请求更新并停用引擎.
Make sure that once you finish getting the location information needed or your activity gets destroyed you remove all listeners, stop requesting updates and deactivate the engine.
这篇关于Mapbox-我可以在没有Mapbox地图的情况下使用locationlistener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!