Accuracy of fromDivPixelToLatLng function

283 views
Skip to first unread message

Jason

unread,
Aug 23, 2012, 4:23:25 PM8/23/12
to google-map...@googlegroups.com
Hi,

I'm trying to make it easier for users to add overlays to the my web app, and to do this I need to have an accurate lat/long point of the div corners.  Complicating this is the fact I've added the jquery rotate library available on google code.

So what I do now is get the top, left, right and height values from the div's CSS.

Assuming that
  • overlay is the OverlayView object described in the custom overlay secion of the documentation and has already been initialized
  • newElement is the new image overlay
  • map is the map view

var overlay = new google.maps.OverlayView
var container = getDocumentById("newElement);

var top = container.style.top;
var left= container.style.left;
var right = container.style.right
var height = container.style.height

var topRight = overlay.getProjection().fromDivPixelToLatLng(new google.maps.Point(top, right));
var bottomLeft = overlay.getProjection().fromDivPixelToLatLng(new google.maps.Point(left, top-height));

My issue is that the topRight and bottomLeft coordinates are off quite a bit.  When I align the image,

topRight has a location of 43.6812604043771, -70.45211922222899 when it should be 43.682516,-70.450773
and bottomLeft has a location of 43.683333966614995, -70.45189391667174 when it should be 43.681413,-70.45168

These coordinates are off by at least 20 meters or so.  Is there a better way to actually calculate the coordinate locations without resorting to a marker drop and drag?

Jeremy Geerdes

unread,
Aug 23, 2012, 6:43:20 PM8/23/12
to google-map...@googlegroups.com
I think you'll find it hard to do this for one big reason: a pixel is not the same thing as a point. A LatLng represents a singular point in space-time, but a pixel has both height and width dimensions. To illustrate the problem, at zoom level 0, the entire earth is 256x256 pixels. This means that 1 pixel is nearly 160 km (100 miles) on a side. While zooming in will mitigate this issue, you will never achieve perfect accuracy converting a pixel coordinate to LatLng.

jg


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/U8dACZMacXEJ.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.



--
Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

Rossko

unread,
Aug 24, 2012, 4:34:44 AM8/24/12
to Google Maps JavaScript API v3
> when it should be 43.681413,-70.45168

Can you expand on why you think it should be that - are you assuming
the imagery is accurate to better than 20m? Which imagery?
Reply all
Reply to author
Forward
0 new messages