Google 地图,get center 不在中心。 Android

Google maps, get center is not on the center. Android

我有一个问题,当我试图获得地图的中心时,它与屏幕的中心不同,并且在不同的设备上存在不同的距离差异。我如何才能获得地图的真正中心?我需要在其中添加一个标记

谢谢

部分XML代码:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical">

    <fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/map" tools:context=".MapsActivity"
        android:name="com.google.android.gms.maps.SupportMapFragment" />

    <ImageView

        android:layout_width="64dp"
        android:layout_height="64dp"
        android:id="@+id/crosshair"
        android:src="@drawable/crosshair"
        android:onClick="btPontoClick"
        android:layout_centerInParent="true"/>

    </RelativeLayout>

Java取中心代码:

public void btPontoClick(View v){
    LatLng latlng =  mMap.getCameraPosition().target;
    addPonto(latlng);
    okParaVoltar = false;
}

目标取决于相机的方位和旋转。 最好的方法是获取地图 "center" 的屏幕点,然后通过以下操作将其转换为地图点:

myMap.getProjection().fromScreenLocation(screenPoint);

https://developers.google.com/android/reference/com/google/android/gms/maps/Projection

注意:

Returns the geographic location that corresponds to a screen location. The screen location is specified in screen pixels (not display pixels) relative to the top left of the map (not the top left of the whole screen).

我用不同的方法解决了这个问题。

现在我将 ImageView 屏幕中的 Position(X,Y) 转换为 LatLng 到 google 地图!

谢谢大家