I am running a PostgreSQL 9.1 Database with PostGIS 1.5 extension. Several coordinates are stored in there with type GEOMETRY (SRID 4326). I'm building a web-application with Google Maps Javascript API v3 to display those points. For any point on the map and a definable distance, I now want to highlight markers if they are within the radius of that point.
This query returns the IDs of all those points:
WITH chosen AS (SELECT * FROM ST_SetSRID (ST_MakePoint ($1, $2), 4326))
SELECT mypoints.id FROM mypoints, chosen
WHERE ST_DWithin (mypoints.location::geography, chosen.ST_SetSRID::geography, $3);
The ::geography casts are needed here to use meters as measurement unit instead of degrees. $1,$2 is lon,lat, $3 is the chosen distance in meters.
Clientside, only the markers resulting from the query receive full opacity and I also display a google.maps.Circle with the chosen distance as radius. As you can see on the picture below, some markers that should be highlighted if you trust the red circle are not returned by my query. The difference also only seems to occur on the X-axis.
Now what is wrong here?
Is the circle shape from the GMaps JS API inaccurate for my region (Germany)?
Or am I missing something in my query?
So far, i really think that martin_f is right about the distortion. There are multiple coordinate systems involved here: https://stackoverflow.com/questions/15015946/google-map-api-v3-projection
Can anybody confirm that every Shape I draw in Google Maps Javascript API is in SRID 3857 and every Marker I add with Lat/Lon Values in SRID 4326 are internally converted to 3857 before they are shown on the map?