I\'m making a small application with Google maps that determines if an entered address is part of a predefined service region.
The user enters an address, and a PHP
There is a bug with this algorithm, when the ray is tangent to the shape. Just add an epsilon to the test point's latitude when it might happen (line 3 of Ilmari's code):
if ($test_point->lat == $p0->lat)
$test_point->lat += 0.0000000001;
Also see http://rosettacode.org/wiki/Ray-casting_algorithm (corrected URL).
Thanks.