getting latitude longitude 0.0 from googleMap.getCameraPosition().target

前端 未结 2 1583
梦毁少年i
梦毁少年i 2021-01-24 01:53

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) getSupport         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 02:34

    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());
        }
    });
    

提交回复
热议问题