【发布时间】: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 项目,而不是尝试继续对他们已弃用但似乎没有现成替代品的定位系统进行排序。但是,如果您一直在观看这些版本,
LocationLayerplugin 的 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