On Nov 19, 12:01 am, robert <[email protected]> wrote:
> Yes it is possible, I was as stuck as you probably were back in the v2
> days and tried a million and a have different ways of figuring this
> out when I come across a solution, I wish I remembered where from so I
> could attribute it to them.

That is from Mike Williams' v2 tutorial:
http://econym.org.uk/gmap/

Third Party Extensions
Part 12 Using EPoly - extra methods for polygons and polylines.
http://econym.org.uk/gmap/epoly.htm

There are several ports of it to v3.

  -- Larry

> However I did port it to v3, it involves
> extending the Polygon class to include a function called Contains,
> which takes in the latlng object and returns back true or false.
>
> The function is as follows:
>
> google.maps.Polygon.prototype.Contains = function(point) {
>
>         var j = 0;
>         var func_oddNodes = false;
>         var x = point.lng();
>         var y = point.lat();
>         var poly = this.getPath();
>
>         for (var i=0; i < poly.getLength(); i++) {
>
>                 j++;
>
>                 if( j == poly.getLength() ) {
>                         j = 0;
>                 } // end if
>
>                 if (  ((poly.getAt(i).lat() < y) && (poly.getAt(j).lat() >= 
> y))
>                 || ((poly.getAt(j).lat() < y) && (poly.getAt(i).lat() >= y)) 
> ) {
>
>                         if ( poly.getAt(i).lng() + (y - poly.getAt(i).lat())
>             /  (poly.getAt(j).lat()-poly.getAt(i).lat())
>             *  (poly.getAt(j).lng() - poly.getAt(i).lng())<x ) {
>
>                                         func_oddNodes = !func_oddNodes
>
>             } // end if
>
>                 } // end if
>
>         } // end for
>
>         return func_oddNodes;
>
> } // end function
>
> And to make the call to it:
>
> mypolygon.Contains(mypoint);
>
> I have it on a site that is up for now, (I'm working to replace it
> soon) its @http://www.cadistrict38.org/new/2011/m.php, just click
> submit on that first pane and then enter in any name and try location
> "Lakewood, CA" and it should spit back "within Lakewood"
>
> Hope this helps!
>
> On Nov 18, 4:43 pm, Zachary DeBruine <[email protected]>
> wrote:
>
>
>
>
>
>
>
> > Given a latitude-longitude point, is there an easy code that I can use to
> > determine whether or not that point is within the bounds of the
> > user-defined geometrical shape?
>
> > Thanks!
> > -Zach

-- 
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.

Reply via email to