# How to write a custom map canvas and project coordinates on it? [closed]

I am writing a game with Objective C ( xcode ) and I need to use the users location service to mark their position on a map but since I need to create my own map component, I am not able to use the Map framework.

Doing this I think I need to project latitude and longitude which I receive from location framework on my custom planar canvas, this is a small part of my game but the other parts are pretty easy or could be done if I could manage to implement this part, however I dont know where to start.

did anybody does it before? is it easy to create a map canvas?

Any kind of hint and help or sympathy are welcome.

Thanks

• This doesn't sound game-dev specific. Have you considered asking on Stack Overflow instead?
– Anko
Commented Aug 29, 2015 at 13:37
• Anko, Maybe you are right, Maybe I should ask this question from GIS community. I will ask it from StackOverflow too but only if no one posts a good and acceptable answer here. Thanks for the suggestion. I don’t have any reputation to set a bounty for it :))) Commented Aug 29, 2015 at 14:06

First you need to know what is an ellipsoid and why we use them. The earth is spherical and to be exact it can be approximated using an ellipsoid. Location Service and all GPS system that work world wide, must use an ellipsoid that fits the best way the earth, Why we need an ellipsoid? because we need a mathematical model to do the computations. for example, suppose you need to know the distance from a specific point on the earth surface to the earth center. How could you do this? you must have the 3D model of the earth and measure the radius at that point. but in the real world we don’t have such a model and we are unable to measure all the points at the surface of the planet but we can only select a countable number of point on surface and using a 3D regression we find a best fitted ellipsoid. since you have a,b and c (diameters) of that ellipsoid, you may calculated each radius for every given latitude and longitude.

So, forget the irregular shape of the earth and assume that the earth is like an ellipsoid and there is no mountain on surface.All GPS and Location Service use a well known ellipsoid called WGS84. sometimes they call ellipsoid, datum. so do not panic if somewhere you saw this word.

Implementation : You need to google the parameter of WGS84 and find its a,b and c. and then you need to manage the map scroll and draw it yourself, to do it, you need to do a transformation from an ellipsoidal coordinates which is a pair of latitude and longitude to a planar cartesian coordinate system I mean the X and Y of the screen of your phone. you need to do the transformation from Lat,Long to X,Y and vice versa (X,Y to Lat,Long). There are different algorithms that do the transformation for you, some use iteration and some are direct method. But I don’t remember the details take a look at the following link

http://kartoweb.itc.nl/geometrics/Map%20projections/Understanding%20Map%20Projections.pdf

In order to model a world wide map, you need to use streaming technology to feed the canvas.

You may also create a new custom canvas class and inherits from CoreGraphics canvas.

If you really like and need to re-invent the wheel and re-write all of the CoreLocation framework and MapKit from sketch, you should consider that it demands a lot of time and cost you a lot. there is many precautions that you may take into consideration while using the data at this scale for Example If you use OpenGL to draw your map elements on your canvas, you need to define a local coordinate system by subtracting a big x and y from all coordinates to make them small enough so they will fit into float the numbers and increase the float accuracy in OpenGL varying and uniform variables. It is very challanging and needs a wide range of knowledge in many fields.

But Hey, I wish you luck.