How to get the location of a centered place on a map like uber android app

Someone please explain to me how to get the location of a centered place on a google map. Like in this Uber app. The user can move the map, but the contact is always centered and we can get the location while we keep moving the map.

enter image description here

+3


source to share


2 answers


I'm not sure which language you are using, so there is a javascript solution here. try to create a latlng variable and use that variable to position the marker and define the center. You could do something like this



var markerLatlng = new google.maps.LatLng ("your coords here");
var mapOptions = {
	zoom :5,
	center: markerLatlng,
	mapTypeId: google.maps.MapTypeId.ROADMAP
	};

var marker = new google.maps.Marker({
	position: markerLatlng,
	map: map,
	animation: google.maps.Animation.DROP,
	title: "your title here",
	});
      

Run code


Hope this helps.

0


source


You can use CurrentCenterPositionMap

First, import the lib:

compile 'br.com.simplepass:mapfragmentwrapper:0.8.0'

      

Then all you have to do is put the MapFragmentWrapper xml tag as the container of your map fragment. Like this:



<br.com.simplepass.mapfragmentwrapper.MapFragmentWrapper
    android:id="@+id/map_wrapper"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/main_fragment_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>

</br.com.simplepass.mapfragmentwrapper.MapFragmentWrapper>

      

See the result:

enter image description here

0


source







All Articles