在google map下,判断点是否在多边形内的函数

来源:互联网 发布:linux查看ssh端口 编辑:程序博客网 时间:2024/05/18 00:57

摘自:

http://appdelegateinc.com/blog/2010/05/16/point-in-polygon-checking/


原理:

http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm


V3版 https://github.com/tparkin/Google-Maps-Point-in-Polygon/blob/master/maps.google.polygon.containsLatLng.js

V2版 http://appdelegateinc.com/samples/Google-Maps-Point-in-Polygon/maps.google.polygon.containsLatLng.js


调用方法:

var coordinate = new google.maps.LatLng(40, -90);                                                                                                                                                                                                       var polygon = new google.maps.Polygon([], "#000000", 1, 1, "#336699", 0.3);var isWithinPolygon = polygon.containsLatLng(coordinate);