[Google Maps API v2] Drawing point + radius, conflicts with backend
So bear with me, as I'm still trying to wrap my head around this. I
have a setup that utilizes PostGIS on the back-end (through geo-
django) and google maps on the front-end.
On the backend I have a point in WGS84 and a radius in KM around it. I
do spatial queries around it by:
- Converting the point to Mercator
- Buffering the point (geo-django) by the radius in meters
- Converting the resulting polygon back to WGS84
This all seems to work, except that I'm noticing a bit of a difference
between what I expect and the results that I'm getting.
So I decided to take that resulting polygon and plot it on a map. Here
is what I got:
Ignore the blue circle. The red circle is what I'm drawing directly by
taking the point and projecting a radius out from it. The green circle
is the polygon as returned from geo-django (the same point + radius,
projected to Mercator, and back to WGS84).
I'm plotting the red circle using a simple algorithm I picked up
somewhere around here. It uses the excellent latlon.js library to to
calculate each point. Here is the relevant code:
LatLon.prototype.destPoint = function(brng, d) {
var R = 6371; // earth's mean radius in km
var lat1 = this.lat.toRad(), lon1 = this.lon.toRad();
brng = brng.toRad();
var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) +
Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/
R)*Math.cos(lat1),
Math.cos(d/R)-
Math.sin(lat1)*Math.sin(lat2));
lon2 = (lon2+Math.PI)%(2*Math.PI) - Math.PI; // normalise to
-180...+180
if (isNaN(lat2) || isNaN(lon2)) return null;
return new LatLon(lat2.toDeg(), lon2.toDeg());
}
Essentially I start at the center and call destPoint() for each node
in the circle (36 nodes) eventually arriving at a closed polygon that
I then add as an overlay. Pretty simple stuff.
Unfortunately my geometry is failing me here. I'm positive that I'm
making some sort of bad assumption (probably around how that
destPoint() function is projecting vs the better representation on the
backend), but I'm not sure what it is.
Help!:)
--
You received this message because you are subscribed to the Google Groups "Google Maps API V2" group.
To post to this group, send email to google-maps-api@googlegroups.com.
To unsubscribe from this group, send email to google-maps-api+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home