Android中的Google地图可以显示指南针方向;如果是这样,怎么样? [英] Can Google Maps in Android show the compass direction; if so, how?

查看:459
本文介绍了Android中的Google地图可以显示指南针方向;如果是这样,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何在Android上的Google地图(API 2)片段中显示设备的位置和方向?内置的地图应用通过小点和箭头显示设备的位置和方向;是否有可能在地图片段中做到这一点?是手动读取传感器和绘制多边形的唯一选择,还是有内置解决方案? 解决方案

这不是一个内置的方式来做到这一点,但它可以与现有的基础设施协同工作。



我的位置图层可以显示GPS报告的位置和GPS报告的方位基于运动)带有箭头指示器。这可以使用 GoogleMap.setLocationSource 和自定义的 LocationSource 类来破解。基础知识是创建一个新的 LocationSource ,使它成为 LocationListener 和一个 SensorEventListener ,然后让它产生一个 Location 对象,该对象使用来自定位系统的数据获取纬度,经度,海拔高度和精度,但是使用磁力计的数据和加速计计算指南针方向并将该数据提供给 Location.setBearing


How do you show a device's location and orientation in a Google Maps (API 2) fragment on Android? The built-in Maps app shows the device's location and orientation with a small dot and an arrow; is it possible to do this in a Map fragment? Is the only option to read the sensors manually and draw polygons, or is there a built-in solution?

解决方案

It's not a built-in way to do this, but it works with the existing infrastructure.

The my-location layer can show the GPS-reported location and the GPS-reported bearing (based on movement) with an arrow indicator. This can be hacked using GoogleMap.setLocationSource with a custom LocationSource class. The basics are to make a new LocationSource, make it a LocationListener and a SensorEventListener, then have it produce a Location object that uses data from the location system for latitude, longitude, altitude, and accuracy, but use data from the magnetometer and accelerometer to calculate the compass direction and provide that data to Location.setBearing.

这篇关于Android中的Google地图可以显示指南针方向;如果是这样,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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