如何在android中的地图触摸位置上动态绘制形状 [英] How to draw a shape dynamically on map touched location in android

查看:140
本文介绍了如何在android中的地图触摸位置上动态绘制形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一个形状,无论用户触摸地图,都应该动态绘制。我对绘制这些形状没有任何想法。我怎么能做到这一点?我可以通过画布完成这件事吗?我使用MapFragment。



请参阅图片, $ b



请给我任何想法!您可以通过添加一个 View 来完成任何帮助!

解决方案

c>叠加地图。


  • 有一个 Polyline 对象(最初为空)将成为你的路线

  • View
  • 处处理onTouchEvent。 to LatLng 使用 Projection
  • 将新的点添加到 Polyline



您完成了。

<请注意,这会消耗所有会以其他方式进行地图平移或缩放的事件。您必须有其他方式与地图进行交互,或者使用某些标志启用消费事件。


I want to draw a shape, wherever the user touches the map, the should be drawn dynamically. I don't have any idea about drawing these shapes. How could I achieve this? Can I get this done through canvas? I am using MapFragment.

Please see the image,

Please give me any idea!! Any help is appreciated!!

解决方案

You can do that by adding a View overlaying the map.

  • have a Polyline object (initially empty) that will be your line
  • handle onTouchEvent on that View
  • translate x,y from events to LatLng using Projection
  • add new point to Polyline

And you are done.

Note that this consumes all the events that would otherwise make map pan or zoom. You will have to have some other way to interact with map or enable consuming events using some flag.

这篇关于如何在android中的地图触摸位置上动态绘制形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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