Central fixed marker in android v2 mapview

I want to set a fixed marker at a central point mapviewwhen dragging a map. It was made on google android map v1 mapview. But now it is out of date. Now my question is: is this possible in android Map V2 google mapview? (I tried. But the map does not appear)

+2
source share
3 answers

I'm sure you used getMapCenter()one that, according to Google Maps for Android v2, is no longer available for use. But don't worry, just use this:

GoogleMap.getCameraPosition().target

LatLng, . , , OnCameraChangedListener GoogleMap.

yourGMapInstance.setOnCameraChangeListener(new OnCameraChangedListener() {
    @Override
    public void onCameraChange (CameraPosition position) {

        // Get the center of the Map.
        LatLng centerOfMap = yourGMapInstance.getCameraPosition().target;

        // Update your Marker position to the center of the Map.
        yourMarkerInstance.setPosition(centerOfMap);
    }
});

. , !

+7

, - , ?

MapView. Map Fragment, , , - ImageView, - :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/fragment1"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/cross_hairs" />

</RelativeLayout>

MapFragment MapView.

, , .

, !

+12

Please note that the setOnCameraChangeListener()outdated, so you can use the new camera listeners ( OnCameraIdleListener, OnCameraMoveListener, OnCameraMoveStartedListener, OnCameraMoveCanceledListener), for example:

map.setOnCameraMoveListener(new GoogleMap.OnCameraMoveListener() {
    @Override
    public void onCameraMove() {
        // Get the center of the map
        LatLng center = map.getCameraPosition().target;
        ......
    }
});

For more information, read the following: https://developers.google.com/maps/documentation/android-api/events

0
source

All Articles