How to get the location of centered place pin on Map like uber android app

3.7k views Asked by At

Someone please explain me how to get the location of centered place pin on Google Map Like in this Uber App. User can move the map but pin is always centered align and We can get the location as we keep moving the map.

enter image description here

2

There are 2 answers

1
DrewtilDeath On

I'm not sure what language your using so here's a javascript solution. try creating latlng variable and using that variable to both place the marker and define 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",
 });

Hope this helps.

0
Leandro Borges Ferreira On

You can use CurrentCenterPositionMap

First import the lib:

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

Then, all you have to do is to put the MapFragmentWrapper xml tag as a 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