You should sjust the Contains function to v3.
The things you need to change is getVertextCount() to (getPath().length im
guessing)
And perhaps some of the other methods, but the base should be the same.
/**
* @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;
};
2010/4/21 Charles <[email protected]>
> Hi, I want to know if it's possible in v3 to know if a polygon
> contains a certain coordinate.
>
> I have polygons representing the districts of a city and users enter
> their address (which I reverse geocode to get the latlng of where they
> live) to know in which district they are. I have no problem with
> drawing polygons or getting the coordinates, the only thing missing is
> getting to know of the coordinate is in a certain polygon.
>
> I know that in v2 there was a GPolygon.contains method but it seems it
> is not in v3. I've searched a lot today and all I found were tutorials
> for binding clicks... this is not what I want.
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-js-api-v3%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>
--
Bjorn Brala
----------------
www.GeoStart.nl/english/ - Google maps - Swis Webdesign
www.twitter.com/bbrala
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.