8

I am designing an application in C++ to view and edit a map of a fictional planet. How it works will be similar to Google Maps. I would like the user to be able to see their current position in latitude/longitude and world coordinates on the GUI.

How can I convert a latitude and longitude values to "world coordinates" and back, as in Google Maps? or to "pixel coordinates" and back?

Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
  • 2
    What are "world coordinates"? – Sjoerd Jun 22 '10 at 07:35
  • @Sjoerd Explanation is here: http://code.google.com/apis/maps/documentation/javascript/overlays.html#WorldCoordinates – Jake Petroules Jun 22 '10 at 07:44
  • 1
    Have you looked at this: http://en.wikipedia.org/wiki/Mercator_projection#Mathematics_of_the_projection – Sjoerd Jun 22 '10 at 07:58
  • Your problem seems somewhat ill-defined. What projection do you want to use when displaying maps? Spherical Mercator (which Google Maps uses) is nice because it's easy to scale down with integral-sized tiles, but for general-purpose cartography it has many drawbacks. If you want to be able to zoom all the way out and see a globe, an azimuthal projection may be your best bet. Also, is your hypothetical planet a sphere, or is it an oblate spheroid like the Earth? That would make a difference as to what latitude and longitude mean on your planet's surface. – Daniel Pryden Jun 23 '10 at 00:18
  • Late response, but I basically just wanted the same math as Google Maps used, which I found described at the link in my answer. – Jake Petroules Jun 26 '10 at 02:20

1 Answers1

11

I found the answer to my question. The formulas for converting between the different coordinate systems can be found in the source code of this example on the Google Maps API website: http://code.google.com/apis/maps/documentation/javascript/examples/map-coordinates.html

Jake Petroules
  • 23,472
  • 35
  • 144
  • 225