【问题标题】:How to get the location of centered place pin on Map like uber android app如何在地图上获取居中位置图钉的位置,如 uber android 应用程序
【发布时间】:2015-08-26 02:29:42
【问题描述】:

请告诉我如何在谷歌地图上获取居中位置图钉的位置,就像在这个优步应用程序中一样。用户可以移动地图,但图钉始终居中对齐,我们可以在不断移动地图时获取位置。

【问题讨论】:

  • 我相信您需要在您的地图实例上调用getCameraPosition() 才能使其正常工作。这个post 回答了您的确切问题,包括如何处理地图上的位置变化(setOnCameraChangeListener)。
  • 我会尝试并更新你。谢谢!!

标签: android google-maps google-maps-api-3 android-maps-v2


【解决方案1】:

我不确定您使用的是什么语言,所以这里有一个 javascript 解决方案。尝试创建 latlng 变量并使用该变量来放置标记和定义中心。你可以做这样的事情

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",
	});

希望这会有所帮助。

【讨论】:

  • @DrewtiiDeath,我需要 android 的帮助,因为它也在标题中提到。无论如何感谢您的回答。
【解决方案2】:

您可以使用CurrentCenterPositionMap

首先导入库:

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

然后,您所要做的就是将 MapFragmentWrapper xml 标记作为地图片段的容器。像这样:

<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>

查看结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    相关资源
    最近更新 更多