android– 在用户位置锁定Google地图

android– 在用户位置锁定Google地图,第1张

概述我希望我的应用程序中的谷歌地图始终完全以用户为中心,并随着当前位置的变化而随之移动.(想想口袋妖怪去,地图实际上如何与用户一起移动)我目前的最佳实现只是每次更改位置时都会使用动画更新摄像机位置,如下所示://updatethelocationofthecamerabasedonth

我希望我的应用程序中的谷歌地图始终完全以用户为中心,并随着当前位置的变化而随之移动. (想想口袋妖怪去,地图实际上如何与用户一起移动)

我目前的最佳实现只是每次更改位置时都会使用动画更新摄像机位置,如下所示:

            // update the location of the camera based on the new latlng, but keep the zoom, tilt and bearing the same        CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraposition(new Cameraposition(latLng,                    GoogleMap.getCameraposition().zoom, MAX_TILT, GoogleMap.getCameraposition().bearing));        GoogleMap.animateCamera(cameraUpdate);        GoogleMap.setLatLngBoundsForCameraTarget(toBounds(latLng, 300));

然而,这使得相机运动有些不稳定并且它落后于实际的用户位置标记,特别是如果用户快速移动.

有没有办法绑定谷歌地图相机的运动,以便它完全匹配用户的运动?

解决方法:

在口袋妖怪围棋的情况下,我不认为该标记实际上在GoogleMap上.如果要在地图中心修复图像(或任何类型的视图)…只需确保图像位于xml文件中地图的中心.

像这样:

<relativeLayout        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent">        <ImageVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_centerInParent="true"            androID:src="@mipmap/ic_self_position"/>        <fragment            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            />    </relativeLayout>

所以现在你在地图的中心有一个标记.好的,但你仍然没有将它与用户位置同步……所以让我们解决这个问题.

我将假设你没有问题来开始你的地图.所以,那样做,我会等.完成了吗?好.地图集.

只是不要忘记在地图中禁用拖动:

@OverrIDe    public voID onMapReady(GoogleMap GoogleMap) {       GoogleMap.getUiSettings().setScrollGesturesEnabled(false);       ...}

让我们收到用户位置并移动地图.

使用此链接:

https://developer.android.com/training/location/receive-location-updates.html

但是将代码的某些部分更改为:

    public class MainActivity extends ActionBaractivity implements             ConnectionCallbacks, OnConnectionFailedListener, LocationListener {         ...         @OverrIDe         public voID onLocationChanged(Location location) {             mCurrentLocation = location;             mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());             moveUser(Location location);         }         private voID moveUser(Location location) {             LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());            mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));     mCharacterImageVIEw.animate(pretendThatYouAreMovingAnimation)[you can make a animation in the image of the user... like turn left/right of make walk movements]        }     } 

如果要在移动方向上旋转角色,则需要将之前的Latlng与新角色进行比较并旋转图像(或视图…或任何内容)以指向移动方向.

如果您需要更多信息,也许这个回购可以帮助您:CurrentCenterPositionMap

(回购不做你想要的……它只使用我解释的相同概念.)

总结

以上是内存溢出为你收集整理的android – 在用户位置锁定Google地图全部内容,希望文章能够帮你解决android – 在用户位置锁定Google地图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1108577.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存