文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Detect a point is inside a polygon with google maps

Detect a point is inside a polygon with google maps

时间:2010-10-15  来源:ALLI Look for Lost Idylls

// Thanks to App Delegate Inc


// For API V2

GPolygon.prototype.contains = function(latLng) {

 var inPolygon = false;

// Exclude points outside of bounds as there is no way they are in the polygon

var bounds = this.getBounds();

if  (bounds!=null && bounds.contiansLatLng) {

// Raycast point in polygon method

var numPoints = this.getVertexCount();

var j = numPoints - 1;

var P = latLng;

for (var i = 0; i < numPoints; i++) {

var P1 = this.getVertex(i);

var P2 = this.getVertex(j);

if (P1.lng()<P.lng() && P.lng()<=P2.lng()) {

if ( (P2.lng()-P1.lng())*(P.lat()-P1.lat()) < (P.lng()-P1.lng())*(P2.lat()-P1.lat()) ) {

inPolygon = !inPolygon;

}

}

j = i;

}

}

return inPolygon;

}


// For API V3

google.maps.Polygon.prototype.contains = function(latLng) {

var inPolygon = false;

var path = this.getPath();

if (path) {

// Raycast point in polygon method

var numPoints = path.getLength();


var j = numPoints - 1;
var P = latLng;
for (var i = 0; i < numPoints; i++) {
var P1 = path.getAt(i);
var P2 = path.getAt(j);
if (P1.lng()<P.lng() && P.lng()<=P2.lng()) {
if ( (P2.lng()-P1.lng())*(P.lat()-P1.lat()) < (P.lng()-P1.lng())*(P2.lat()-P1.lat()) ) {
inPolygon = !inPolygon;
}
}
j = i;
}

}

return inPolygon;

}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载