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

╄→гoц情女王★ 提交于 2019-12-06 08:17:10

问题


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.


回答1:


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:




回答2:


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.



来源:https://stackoverflow.com/questions/30763093/how-to-get-the-location-of-centered-place-pin-on-map-like-uber-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!