Mapbox - Can I use the locationlistener without Mapbox map

江枫思渺然 提交于 2019-12-12 04:58:16

问题


I know the way to use locationListener and triggering the GPS is done like that:

mapboxMap.setMyLocationEnabled(true);

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.

How can I do with Mapbox ?


回答1:


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.




回答2:


The answer is no! You cannot do it and I recommend you should not do it as it will increase your apk size a lot. If you just need the location listener, there're a lot of libraries which can do it for you as: Smart Location Library:

SmartLocation.with(context).location()
.start(new OnLocationUpdatedListener() { ... });


来源:https://stackoverflow.com/questions/45406819/mapbox-can-i-use-the-locationlistener-without-mapbox-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!