越来越纬度经度0.0从googleMap.getCameraPosition()。目标经度、纬度、目标、getCameraPosition

2023-09-07 01:14:33 作者:白衣影眠梦

我试图让纬度地图的中心和纬度。我使用的片段显示地图就是

I was trying to get latitude and longitude of center of the map. I am using Fragment to show map that is,

SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                                    .findFragmentById(R.id.mapID);
if (fm != null) {
    googleMap = fm.getMap();
}
LatLng loc = googleMap.getCameraPosition().target;

我打印这个禄和我得到的价值为0.0,0.0。我没有得到我要去的地方错了。

I am printing this loc and i am getting value as 0.0, 0.0. I am not getting where i am going wrong.

我试图用 VisibleRegion 也得到纬度地图,甚至是中心没有帮助和经度。

I tried to use VisibleRegion also to get latitude and longitude of center of map but even that did not help.

推荐答案

您所请求的摄像机位置时,地图上还没有装,因此相机指向0.0,0.0。相反,使用这样的:

You are requesting the camera position when the map was not yet loaded, therefore the camera is pointing to 0.0, 0.0. Instead use this:

googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
    @Override
    public void onMapLoaded() {
        Log.e("TAG", googleMap.getCameraPosition().target.toString());
    }
});