旋转Google地图以显示我的实时路线 [英] ROTATE Google-Map to display my real-time DIRECTION

查看:129
本文介绍了旋转Google地图以显示我的实时路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Maps Android API v2,在其中我将设备位置显示为地图上的GoogleMap标记. 我有一个侦听器(LocationServices.FusedLocationApi.requestLocationUpdates ...)附加到地图,以便处理每个GPS位置更改. 每次收到新位置时,我都会更新标记(我的位置)以及地图上的摄像头,并且几乎显示出我在开车时正在移动.

I am using the Google Maps Android API v2 where I display my Device location as a GoogleMap Marker on a Map. I have a listener (LocationServices.FusedLocationApi.requestLocationUpdates...) attach to the Map in order to handle every GPS location change. Every time I receive a new location I update the Marker (my position) as well as the Camera on the Map and pretty much it shows like I am moving as I drive.

但是...我需要一些帮助,以使MAP 旋转和/或显示与我移动的方向相同.我的意思是,我开车时需要旋转MAP,以便在地图左侧可以看到现实生活中的左侧,右侧也一样.由于MAP方向是静态的,因此标记(Me)在其上移动,但大多数情况下该方向与我的汽车实时方向不匹配.

However... I need some help in order to have the MAP rotate and/or display on the same direction that I am moving to. I mean, while I drive I need to rotate the MAP where I can see on my map-left-side what I have on my real-life-left-side, and so the same with the right. Since the MAP direction is static, the Marker (Me) is moving on it but most of the time the direction does not match my car real-time direction.

我该如何处理地图才能实现这种视觉效果?

What should I do with the Map in order to accomplish this visual effect?

推荐答案

我正在猜测Google Map API不提供这种常见视觉效果的可能性.我错了...它叫做 BEARING .

I was guessing how is posible that the Google Map API does not provide such common visual effect desire. I was wrong... it's called BEARING.

private void updateCameraBearing(GoogleMap googleMap, float bearing) {
    if ( googleMap == null) return;
    CameraPosition camPos = CameraPosition
            .builder(
                    googleMap.getCameraPosition() // current Camera
            )
            .bearing(bearing)
            .build();                   
    googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(camPos)); 
}

自从我将位置更改设置为每2秒收到通知...

Since I setup my location changes to be notified every 2 seconds...

    mLocationRequest = LocationRequest.create()
                        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                        .setInterval(POLLING_FREQ_2SECONDS)
                        .setFastestInterval(FASTEST_UPDATE_FREQ_2_SECONDS)

我在同一位置处理新位置以及更新相机(新轴承):

I use that same place to process the new location as well as to update the Camera (new BEARING):

public void onLocationChanged(Location location) {

 // ... process location

 updateCameraBearing(googleMap, location.getBearing());
}

测试+工作=完成!

这篇关于旋转Google地图以显示我的实时路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆