GPS position to grid

Nieles

New member
Joined
Jan 23, 2013
Messages
3
Hi all,

I am writing a program and I stumbled upon a problem.
In the program I want to know the position on a grid based on the users GPS position with Longitude(-180, 180) and Latitude(-90, 90).

Every cell in the grid is 10x10, so if a user walks 100 meters west he should have moved 10 cells to the left on the grid.
My problem is that the longitude increases much faster near the north and south pole then it does around the equator.
100 meter west in sweden should be 10 cells left and in spain 100 meter should also be 10 cells.
And also I don't want negative grid positions. (longitude and Latitude can be negative)

In my mind the grid would look something like this:
WorldGrid.jpg
The more north or south you are on the planet the less dense the grid becomes.

I hope this story is clear and that someone can help me out, my head almost explodes at the moment...
 
Hi all,

I am writing a program and I stumbled upon a problem.
In the program I want to know the position on a grid based on the users GPS position with Longitude(-180, 180) and Latitude(-90, 90).

Every cell in the grid is 10x10, so if a user walks 100 meters west he should have moved 10 cells to the left on the grid.
My problem is that the longitude increases much faster near the north and south pole then it does around the equator.
100 meter west in sweden should be 10 cells left and in spain 100 meter should also be 10 cells.
And also I don't want negative grid positions. (longitude and Latitude can be negative)

In my mind the grid would look something like this:
View attachment 2551
The more north or south you are on the planet the less dense the grid becomes.

I hope this story is clear and that someone can help me out, my head almost explodes at the moment...
A degree of latitude is the same wherever you are (60 nautical miles), but a degree of longitude narrows as you depart from the equator, converging to zero at the poles. The exact formula that E-W distance is proportional to the cosine of the latitude. Your GPS readings would map to
(latitude, longitude × cos(latitude))
Your cells are not squares; if you go north or south you will not always be the same cell index in the E-W direction.

Check this site:
http://www.nationalatlas.gov/articles/mapping/a_projections.html
 
A degree of latitude is the same wherever you are (60 nautical miles), but a degree of longitude narrows as you depart from the equator, converging to zero at the poles. The exact formula that E-W distance is proportional to the cosine of the latitude. Your GPS readings would map to
(latitude, longitude × cos(latitude))
Your cells are not squares; if you go north or south you will not always be the same cell index in the E-W direction.

Check this site:
http://www.nationalatlas.gov/articles/mapping/a_projections.html

But this will result in user near the poles moving a lot faster over the grid then the user near the equator.
This is something I want to prevent.

I tried some calculation with points I measured from google maps, all points are ~141.4 meters (100 east x 100 north) apart from each other.


Points in Sweden: (17.38442, 62.274223) and (17.38633, 62.275138)
Points in Spain: (-1.28089, 38.44563) and (-1.27974, 38.44656)
(longitude, latitude)

Swedish point:
point 1 = (62.274223, (17.38442 × cos(62.274223)) x 10000 = (147509, 622741)
point 2 = (62.275138, (17.38633 × cos(62.275138)) x 10000 = (147609, 622751)
X differences 100, Y differences 10

Spanish points:
point 1 = (38.44563, (-1.28089 × cos(38.44563)) x 10000 = (-9403, 384456)
point 2 = (38.44656, (-1.27974 × cos(38.44656)) x 10000 = (-9385, 384466)
X differences 18, Y differences 10

In other words, people will move faster over the grid to east and west then they do north and south.
And people closer to the poles do this even faster.
I need a formula that converts this correctly, that 100 meters west to east is always 10 left and right on the grid. No matter where you are on earth. (if possible)
 
Last edited:
I think you are missing the point of Dr. Phil's post.

Speed is invariant: 1 meter per second is the same at every degree of longitude.

What is not invariant is the distance between lines of longitude. So, as you already understand, at the same rate of speed for the same period of time, you cross more lines of longitude the farther north (or south) of the equator you are.

What Dr. Phil is saying in effect is that you cannot use rectangular cells for your grid. One way to proceed would be to use trapezoids for your cells except for the top and bottom rows, which must be triangles. (Even this will be only an approximation: you cannot model a curved surface onto a flat service and maintain all relationships unchanged. That is why map makers use different projections: each type of projection preserves a relationship at the expense of other relationships.) http://en.wikipedia.org/wiki/Map_projection

As for your desire to use only positive numbers, that is possible. You could start numbering from one side or the other. Of course, even then signs get reversed when you go in the opposite direction. Furthermore, you will have to take into account that the numbers suddenly jump when you fall off the edge of your grid and reappear on the other side.
 
Last edited:
B
Points in Sweden: (17.38442, 62.274223) and (17.38633, 62.275138)
Points in Spain: (-1.28089, 38.44563) and (-1.27974, 38.44656)
(longitude, latitude)
If you move 100 m North, and 10,000 km = 90°,
then the change of latitude should be about 0.0009° (anywhere on earth).

For your two points in Sweden, you found 0.000914°
and for the two points in Spain, you found 0.00093°
[close enough?]

A degree of longitude is a shorter distance by a factor of cos(latitude),
or your 100 m motion East is a larger number of degrees longitude ..
For latitude 62.3°, I would expect 100 m to be 0.00194° (compared to your observation of 0.00191°)
and at latitude 38.4°, 100 m should be 0.00115° (compared to your observation of 0.00115°).

Multiply degrees by cos(latitude) when converting to distance.
Divide distance by cos(latitude) when converting to longitude.
 
First of all, thank you all for helping me out!
But I think we are still not on one line, or I am still not getting it :)

I am not trying to map the world or to place users on a map of earth.
Users are placed in a fictional world (it's a game), in this world the user sees a grid and based on his location he places on the grid.
The user only sees his surrounding so he doesn't need to know that it's not a perfect mapping of earth :)
Now when the user starts walking (with his phone) he should move 1 cell for every 10 meters.
So 10 meters should always convert to 1 cell (ingame value).

What happens at the moment for the Swedish player is that he will be move 1 grid up for every ~10 meters north but 1 grid left for every ~1 meter west.
So the question would be, how can I make sure that the Swedish player moves 1 grid spot left or right for every 10 meters east or west.
And the same for the Spanish player or any other player in the world.

(I know that there is going to be a problem somewhere halfway the pacific ocean where the longitude will jump from 180 to -180, but I don't expect many players to play my game there in a boat, neither on the north or south pole :) )
PS(the point measurements are not be 100% accurate).
 
If it is a fictional world, why are you worried about real world issues. Make it a cylindrical world; a cylinder maps onto a recatangular grid just fine.
 
Top