Here is my problem. I'm mapping a region in Google Maps after that I'm saving the coordinates in PostGIS database as geographic polygon type.
The goal of my script is to find the closest region to a given point selected from Google Maps.
Here is my solution which is not working very well.
So what I'm doing is to break the region polygon and to find the closest point to my desire point. But the accuracy is not very precise. Some times when my point is closer to a given region it selects a region which is pretty far from it.
SELECT ST_Distance ( ST_GeographyFromText('SRID=4326;POINT(" . $point->longitude . " " . $point->latitude . ")'), geom::geography ) AS distance FROM ST_DumpPoints (gis_coords::geometry) --gis_coords is the region column. ORDER BY distance ASC LIMIT 1 ) AS distance
When I try to render my region column with QGIS and OpenLayers Plugin the result is pretty disturbing.
I'm setting the region layer CSR to WGS 84 (EPSG:4326) and for OpenLayers WGS 84/Pseudo Mercantor (EPSG: 3857)