Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Google Map Point is in polygon from PHP

I've been looking for a way to check if a point is part of a polygon; this polygon is loaded from a file.

All the answers related to this question are solved with javascript, but I require to do this on server-side; this because the result does not need to be shown to the user as a webclient, it needs to be stored and later be used as a parameter to select a group of users (that use the system) inside that area (polygon).

I looked for a Google Maps API for PHP but it looks like it does not exists at all. I found this one, but it is not related to Google and also focuses on the front end.

I also looked for a REST API; it would have been relatively easy to load the content to my php and parse it, but looks like Google put all its efforts on the JS API.

Is there any workaround for this?

Edit 1: As @Spacedman requested, the file format is a KML

Clarification 1: I expected that Google provide a tool for this (as it exists with JS); parsing the file to check via an algorithm is a posibility and I'll have to check if it works properly.

like image 841
Absulit Avatar asked Jul 21 '13 06:07

Absulit


1 Answers

Did you try searching for "php point in polygon" in your favourite search engine? Top hit:

http://assemblysys.com/php-point-in-polygon-algorithm/

It uses a scanline algorithm, and there's some examples. All you need to do is read your polygon file into the right format (you neglected to say what format you have) and call the function.

like image 101
Spacedman Avatar answered Sep 30 '22 05:09

Spacedman