谷歌地图,获取中心不在中心。安卓

关闭

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

谢谢

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;
}
关闭

我以另一种方式解决了这个问题。

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

谢谢你们

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章