I have a polygon, how to know Technical Info point is the inside of my polygon

92 views
Skip to first unread message

franklinNY

unread,
Aug 4, 2011, 3:24:28 AM8/4/11
to google-map...@googlegroups.com
I have a polygon, how to know Technical Info point is the inside of my polygon,
I would like to display just the marker whose coordinates are the one in my polygon

Chris Broadfoot

unread,
Aug 4, 2011, 3:25:46 AM8/4/11
to google-map...@googlegroups.com
Try here:
On Thu, Aug 4, 2011 at 5:24 PM, franklinNY <emilefrankl...@gmail.com> wrote:
I have a polygon, how to know Technical Info point is the inside of my polygon,
I would like to display just the marker whose coordinates are the one in my polygon

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/Gbd7VS5I43EJ.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Bob Tedlar

unread,
Aug 4, 2011, 5:01:30 AM8/4/11
to Google Maps JavaScript API v3

Exact : the same questions generally lead to the same answers !

http://groups.google.com/group/google-maps-js-api-v3/search?hl=en_US&...

/**
* @desc Check if polygon contains point.
* @return boolean
**/
GPolygon.prototype.Contains = function(point) {
var j=0;
var oddNodes = false;
var x = point.lng();
var y = point.lat();
for (var i=0; i < this.getVertexCount(); i++) {
j++;
if (j == this.getVertexCount()) {j = 0;}
if (((this.getVertex(i).lat() < y) && (this.getVertex(j).lat()
>= y))
|| ((this.getVertex(j).lat() < y) && (this.getVertex(i).lat() >=
y))) {
if ( this.getVertex(i).lng() + (y - this.getVertex(i).lat())
/ (this.getVertex(j).lat()-this.getVertex(i).lat())
* (this.getVertex(j).lng() - this.getVertex(i).lng())<x ) {
oddNodes = !oddNodes;
}
}
}
return oddNodes;
};



Esa

unread,
Aug 4, 2011, 10:04:04 AM8/4/11
to Google Maps JavaScript API v3
Right. Looks like a section of Mike Williams' Epoly library. That is
in v2 syntax. Larry has ported that to v3:
http://www.geocodezip.com/scripts/v3_epoly.js

That works fine if you have a single path polygon. To be precise, v3
enables multipath polygons (holes and islands on holes). So a full v3
port would need a few more lines.

The original algorithm is explained here:
http://alienryderflex.com/polygon/
Reply all
Reply to author
Forward
0 new messages