在Google地图上使用鼠标绘制多边形 [英] Draw polygon using mouse on google maps

查看:452
本文介绍了在Google地图上使用鼠标绘制多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用鼠标绘制多边形并在Google地图上标记特定区域。目的是在谷歌地图上标记一个区域,然后显示该地区的酒店和景点。用户将在Google地图上标记酒店,同时创建它们,以便分贝具有经度和纬度。



如何绘制多边形并用颜色填充颜色作为背景以标记Google地图中的区域?我已阅读API手册如何绘制多边形?基本上你需要标记多个点,然后将它们组合成一个多边形。但我需要使用鼠标拖动来完成此操作,就像绘制一个形状一样。请帮助我解决这个问题。

解决方案

您可以在appplication中使用Google MyMaps多边形编辑工具,也许这会 b
$ b

请参阅 http://googlemapsapi.blogspot.com/2008/05/love-my-maps-use-its-line-and-shape.html



然而,如果你想自己实现它,它基本上是这样的:

添加点击监听器来映射。

p>

重复:
存储用户在数组中点击的点数,并在此处添加标记。
如果它是第一个标记添加点击监听器



当用户点击第一个标记时,parse使用点数组来构建多边形



我没有任何代码可以显示给你,但我已经在一家公司实现了这个功能,所以可以这样做:)


I need to draw polygon using mouse and mark a particular area on Google maps. The purpose is to mark an area on Google maps and then showing hotels and attractions on that area. The user will mark the hotels on Google map while creating them so the db will have their latitude and longitudes.

How can I draw the polygon and fill it with a color as background to mark the area in Google Maps? I have read the API Manual "how to draw polygons?" basically you would need to mark multiple points and then combine them into a polygon. But I will need to do this using mouse drag, just like drawing a shape. Kindly help me out how to achieve this.

解决方案

you can use the Google MyMaps polygon editing tools in your appplication, maybe this will be ok for you?

see http://googlemapsapi.blogspot.com/2008/05/love-my-maps-use-its-line-and-shape.html

However if you want to implement this yourself it is basically this:

add click listener to map.

repeat: store points that user clicks on in an array, and add a marker at this point. if it is the first marker add click listener to it

when user clicks on first marker, parse use the array of points to build your polygon

I don't have any code to show you, but I have implemented this myself in a previous company, so it can be done :)

这篇关于在Google地图上使用鼠标绘制多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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