修复标记位置,而不是像 pokemon go 那样映射旋转/方位(方向)
Fix Marker position instead map Rotation/ bearing(orientation) like pokemon go
我正在开发 android 应用程序使用地图来跟踪用户位置。我想在屏幕上修复我当前的位置标记。在我当前的工作演示中,当我旋转地图时,当前位置标记隐藏在屏幕下或移动到另一个位置。我应该如何实现这一目标?提前致谢。
如果你想让标记总是回到屏幕中央,你可以使用:
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng).zoom(zoom).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
这里,latLng保存了marker的经纬度,每次改变marker的位置,或者想让marker回到中心,可以用上面的代码。
此外,您可以使用以下代码防止地图被拖动:
googleMap.getUiSettings().setScrollGesturesEnabled(false);
这将禁止地图四处移动,但旋转、平移和缩放可以正常工作。
如果我对你的理解是正确的,那么你将不得不做一些修改。抱歉,您没有提供代码,所以我不太可能提示您确切的解决方案。但我可以解释想法。
您在 FrameLayout 中放置两个视图的想法:MapView 和 View(对伪代码感到抱歉)。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:id="@+id/touch_zone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
</FrameLayout>
这样你就可以防止触摸地图。然后你需要让你的地图跟踪你的位置
例如,您可以在位置更改时捕获事件并调用 googleMap.animateCamera(...)
。
然后对于 touch_zone 视图,您需要使用您的匿名 class 调用 setOnTouchListener
,这将处理我们上层视图的触摸。在这种方法中,您将实现在屏幕上获取坐标的逻辑,从而投影到地图上的坐标并实现您需要旋转地图的位置。
我正在开发 android 应用程序使用地图来跟踪用户位置。我想在屏幕上修复我当前的位置标记。在我当前的工作演示中,当我旋转地图时,当前位置标记隐藏在屏幕下或移动到另一个位置。我应该如何实现这一目标?提前致谢。
如果你想让标记总是回到屏幕中央,你可以使用:
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng).zoom(zoom).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
这里,latLng保存了marker的经纬度,每次改变marker的位置,或者想让marker回到中心,可以用上面的代码。
此外,您可以使用以下代码防止地图被拖动:
googleMap.getUiSettings().setScrollGesturesEnabled(false);
这将禁止地图四处移动,但旋转、平移和缩放可以正常工作。
如果我对你的理解是正确的,那么你将不得不做一些修改。抱歉,您没有提供代码,所以我不太可能提示您确切的解决方案。但我可以解释想法。
您在 FrameLayout 中放置两个视图的想法:MapView 和 View(对伪代码感到抱歉)。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:id="@+id/touch_zone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
</FrameLayout>
这样你就可以防止触摸地图。然后你需要让你的地图跟踪你的位置
例如,您可以在位置更改时捕获事件并调用 googleMap.animateCamera(...)
。
然后对于 touch_zone 视图,您需要使用您的匿名 class 调用 setOnTouchListener
,这将处理我们上层视图的触摸。在这种方法中,您将实现在屏幕上获取坐标的逻辑,从而投影到地图上的坐标并实现您需要旋转地图的位置。