Mapbox-我可以在没有Mapbox地图的情况下使用locationlistener [英] Mapbox - Can I use the locationlistener without Mapbox map

查看:223
本文介绍了Mapbox-我可以在没有Mapbox地图的情况下使用locationlistener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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