Raycasting algorithm with GPS coordinates

前端 未结 3 1046
庸人自扰
庸人自扰 2021-01-06 17:57

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

3条回答
  •  逝去的感伤
    2021-01-06 18:10

    Well.... your second if() does not compensate for the fact that any of the subtractions may result in a negative number; it would only work if the coordinates are strictly ordered.

    Update: On http://rosettacode.org/wiki/Ray-casting_algorithmn there's a whole bunch of algorithms in various languages that describe the process in detail (unfortunately, there is no version for PHP). What seems to be missing from your solution is picking a point that's guaranteed to be outside of the polygon; since you're dealing with longitude/lattitude that should be easy. Second, make sure your polygon is closed (i.e. go from the last point back to the first, if Google Maps doesn't already do so)

提交回复
热议问题