On Oct 26, 5:30 pm, Nick <[email protected]> wrote: > That's exactly what my issue is. I have a "real" (green) circle that > is properly projected (by converting to World Mercator and back to > WSG84). I'm trying to come up with an algorithm that can nicely > project a very similar circle on-the-fly on the client side. It > doesn't have to be a perfect match, but come fairly close. > > So another way of posing the question: > > Given a lat/lon and a radius in KM, how would I draw a circle that > fairly accurately represents that on a map?
That won't be a "real" circle on the map, it will be an ellipse (how much it diverges from a circle will depend on where it is). I believe you already have the code to calculate it. (the code from http://www.movable-type.co.uk/scripts/latlong.html) You could change the code to use a more accurate ellipsoidal model of the earth: http://www.movable-type.co.uk/scripts/latlong-vincenty.html (but I doubt that is what you are seeing) -- Larry > > Nick > > On Oct 26, 6:16 pm, "[email protected]" <[email protected]> > wrote: > > > > > On Oct 26, 3:49 pm, Nick <[email protected]> wrote: > > > > 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: > > > >http://imgur.com/5Mdrj.png > > > > 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!:) > > > Can't really tell without a link to the code that creates all the > > circles. > > > Are you trying to draw a real circle or something that looks like a > > circle on a google map after projection? > > > They won't be the same and it sounds like you are comparing a real > > circle with something that looks like a circle and are confused > > because they are different. > > > -- Larry- Hide quoted text - > > - Show quoted text - -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.
