【问题标题】:Mapbox get current location, AndroidMapbox获取当前位置,Android
【发布时间】:2018-08-31 14:43:57
【问题描述】:

我正在尝试使用 Mapbox SDK for Android 获取用户的当前位置。在查看了教程和其他所有可用的内容后,我得出结论,显示的所有技术都包括不推荐使用的方法。

我尝试使用以下技术,因为可能是我唯一的方法,但我遇到了一个我无法解决的错误:error: cannot access LocationListener class file for com.google.android.gms.location.LocationListener not found

这是我产生错误的部分代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    context = this;
    super.onCreate(savedInstanceState);
    Mapbox.getInstance(this, API_KEY);

    setContentView(R.layout.activity_map_view_test);


    locationEngine = GoogleLocationEngine.getLocationEngine(context);

    myLocation = locationEngine.getLastLocation();


    mapView = (MapView) findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(final MapboxMap mapboxMap) {
            mapboxMap.addMarker(new MarkerOptions()
                    .position(new LatLng(myLocation.getLatitude(),myLocation.getLongitude()))
                    .title("My Location")
                    .snippet("Illinois")
            );

            mapboxMap.setLatLng(mapboxMap.getMarkers().get(0).getPosition());
        }
    });
}

有人有什么好主意吗?任何帮助都将不胜感激。

最好的问候,

迪米塔尔·格奥尔基耶夫

【问题讨论】:

  • 几个月前我搁置了我的 Mapbox 项目,而不是尝试继续对他们已弃用但似乎没有现成替代品的定位系统进行排序。但是,如果您一直在观看这些版本,LocationLayer plugin 的 v0.5 于本周发布,并声称它是"offers parity with the old MyLocationView API and should be the preferred tool for displaying user's location going forward"。试试看?
  • @HEATH3N 非常感谢您的回复。我也想弄清楚,但不是我没有成功。我将尝试使用 LocationLayer,但我几乎要放弃并尝试使用其他一些开源地图提供程序。
  • @DimitarGeorgiev 您想从哪里获取位置表单 mapbox api 或 google api?
  • 来自 Mapbox API。整个想法是在法线贴图上制作一个带有图片的图层,它可以看起来像室内贴图。但显然这不会发生,所以我决定暂时跳过这个功能。

标签: java android mapbox mapbox-android


【解决方案1】:

如果您在Gradle 中启用了shrink resources,请检查您的Proguard Rules

【讨论】:

    【解决方案2】:

    你真的需要使用谷歌LocationEngine吗?我使用过MapBox SDK 提供的LocationEngine,结果非常好用。您可以尝试导入:

    com.mapbox.android.core.location.LocationEngine;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 2012-01-22
      • 2016-07-30
      • 2012-03-05
      相关资源
      最近更新 更多