Android Canvas - 绘制一个点并根据 GPS 移动重新定位它的回调
我是 android 新手,刚刚研究过 canvas API。我目前有一个名为“MyMap”的活动类和一个名为“MapView”的ViewClass(它扩展了视图)。
MyMap 活动将内容视图设置为 MapView,在 MapView 内,我使用地图的位图图像创建画布,然后根据移动设备当前的 GPS 坐标在地图上绘制一个圆圈。我想知道每当 GPS 坐标发生变化时如何对 draw() 方法执行一些回调?这段代码也会出现在 MyMap 活动中还是 MapView 中?
I am new to android and i've just been looking into the canvas API. I currently have an activity class called "MyMap" and a ViewClass called "MapView" (which extends view).
The MyMap activity sets the content view to MapView and inside MapView I am creating a canvas with a bitmap image of a Map and I am then drawing a circle on the map based on the current GPS coordinates of the mobile. I want to know how do I perform some callback to the draw() method whenever the gps coordinates change? also will this code go in MyMap activity or in the MapView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要做的是首先设置一个 GPS 侦听器并对其做出响应,您可以在此处找到相关信息 LocationManager
它看起来像这样。请记住,GPS 会消耗电池,有很多方法可以做得更好,但这里是它的核心,或多或少
一旦你完成了设置,只需在 onLocationChanged 侦听器中执行你需要执行的操作
代码片段 - 不完整
画圆 - 您需要确定位置和半径
What you need to do is first setup a gps listener and respond to that, you can find information about that here LocationManager
It would look something like this. Keep in mind that GPS sucks battery, there are ways to do this better but here is the meat of it, more or less
Once you have that setup just do what you need to do in the onLocationChanged listener
CODE SNIPPET - NOT COMPLETE
Painting the circle - you will need to determine the positioning and radius