gpt4 book ai didi

android - 将位置转换为 LatLng

转载 作者:行者123 更新时间:2023-12-03 23:17:29 25 4
gpt4 key购买 nike

我正在尝试在当前位置设置标记,因此我尝试将 Location 转换为 LatLng 类:

LatLng mCurrentPlace= new LatLng(location.getLatitude(),location.getLongitude());

然后我又想起了 addMarker 方法:
 mMap.addMarker(new MarkerOptions()
.title(getString(R.string.default_info_title))
.position(mCurrentPlace)
.snippet(getString(R.string.default_info_snippet)))

但是通过“运行”启动应用程序,它被逮捕了。

我哪里错了?

谢谢。

最佳答案

  public void moveMap(GoogleMap gMap, double latitude, double longitude) {
Log.v(TAG, "mapMoved: " + gMap);
LatLng latlng = new LatLng(latitude, longitude);
CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(latlng, 6);
gMap.addMarker(new MarkerOptions().position(latlng));
gMap.moveCamera(cu);
}

在您想要位置和标记的位置以及在 mapasync 回调方法中调用此方法。
@Override
public void onMapReady(GoogleMap googleMap) {

MapsInitializer.initialize(context);
gMap = googleMap;
gMap.getUiSettings().setMapToolbarEnabled(false);
gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if(items.get(getLayoutPosition())!=null )
moveMap(gMap,latitude, longitude);
}
public void initializeMapView() {
if (mapView != null) {
// Initialise the MapView
mapView.onCreate(null);
// Set the map ready callback to receive the GoogleMap object
mapView.getMapAsync(this);

}
}

覆盖 onMapReadyCallback 方法并执行此操作。

Call initializeMapView method in onCreate() or In adapter onBindViewHolder

关于android - 将位置转换为 LatLng,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47672666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com