0

次のマップと、OnCameraIdleListenerを使用してカメラをセンタリングするときのアドレスを取得しますが、イメージでわかるように、マーカーの中心のアドレスを取得しています、あなたが望むものではありません。 私は何か提案を感謝します。そして、画像で私の英語オーバーレイマーカーの正確な位置を取得する方法

を気の毒アドレスは

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:orientation="vertical"> 


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

    <ImageView 
     android:id="@+id/imvCurrentMarker" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ic_a_marker" /> 

    </RelativeLayout> 

enter image description here "スクレ..." ノーL.Jaimes ......

@Override 
public void onCameraIdle() { 

    Log.i(TAG, "onCameraIdle"); 
    LatLng position = mMap.getCameraPosition().target; 
    if (position != null) { 
     mCurrentLocation.setLatitude(position.latitude); 
     mCurrentLocation.setLongitude(position.longitude); 
     retrieveAddress(position); 
    } 
} 

マイマップフラグメントでなければなりません

答えて

0

これは、GoogleマップでこのタイプのUIでよく発生する問題です。しかし、私はあなたがトリックを行うことでそれを達成できることを知っています。

)まず、GoogleマップのAndroid SDKで指定されたfunction of Projectionを使用することをおすすめします。私はtoScreenLocation(LatLng center)について話しています。このプロパティは、LatLng座標に対応する正確なスクリーンポイントを取得するのに役立ちます。この方法を使用すると、[パディング]を設定してマップの表示部分を減らしても、マップの投影の中央にマーカを簡単に配置できます。

ここで興味深い部分は、ドロアブルが正しい位置になるようにすることです。

b)ビュー/ドロウアブルの高さと幅を取得します。ドロウアブルが中央に配置されているので、この中心で新しい位置を設定する必要があります。だから、それを達成するためには、2つに分割された幅のサイズを取得する必要があります。これは新しい位置がリセットされたためです。

c)最後に、高さのサイズで、幅の半分を水平に移動します。

// a) Get center screenPoint. 
    Point screenPoint = mMap.getProjection().toScreenLocation(map.getCameraPosition().target); 
    // b) Get center position of drawable. 
    int fixPlaceMarkerPointX = (imvCurrentMarker.getWidth()/2); 
    int fixPlaceMarkerPointY = (imvCurrentMarker.getHeight()); 
    // c) Set new position for the marker. 
    imvCurrentMarker.setY(screenPoint.y + fixPlaceMarkerPointY); 
    imvCurrentMarker.setX(screenPoint.x - fixPlaceMarkerPointX); 

d)私は別のアプローチがあり、最も簡単だがクーラーではないと思います! haha これはちょうど、負のマージンで高さの合計サイズで移動します。 高さは50dpですので、top_margin = "-50dp"としてください。 さらにもう一つは、centerInParentをマーカーDrawableに入れるだけです。

<ImageView 
    android:id="@+id/imvCurrentMarker" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_centerInParent="true" 
    android:src="@drawable/ic_a_marker" /> 

この情報が役立ちますようお願いいたします。

関連する問題