I have used mapFragment to show google map in my app. I wanted to get latitude and longitude of center of the map.
I have placed marker image at center of the map in xml file,
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/marker_image"
/>
So this places marker at center of the screen so as user drags map i should be able to get latitude and longitude of the center of the map.
This is what i used to get center of the map,
VisibleRegion visibleRegion = googleMap.getProjection()
.getVisibleRegion();
Point x = googleMap.getProjection().toScreenLocation(visibleRegion.farRight);
Point y = googleMap.getProjection().toScreenLocation(visibleRegion.nearLeft);
Point centerPoint = new Point(x.x / 2, y.y / 2);
LatLng centerFromPoint = googleMap.getProjection().fromScreenLocation(
centerPoint);
Issue is i am getting value of centerFromPoint LatLng value as 0.0.
I even tried to use
LatLng loc = googleMap.getCameraPosition().target;
Even in this case i am getting loc value as 0.0.
I am not able to figure out why i am not getting latitude and longitude value.