0

I am new to PHP, and am attempting to build a basic php website for a university project. The aim of the site is to compare GPS co-ordinates (using the abs() function) in order to find the closest parking space to a given landmark.

I have all of the GPS Co-ordinate data stored in my database, and can so far manage to retrieve it using mysql_fetch_array functions and echo it, but I am unsure of how to isolate a given landmark or parking from an array, and then compare the two.

Any suggestions would be greatly appreciated.

  • By GPS co-ordinates do you mean WGS84? There are many co-ordinate systems and it's really only by convention that your GPS receiver displays your position to you in any given format. How far apart will these distances be? i.e. do you need to account for the curvature of the Earth? How about the non-spherical nature of the Earth? What sort of approximation do you require? – Lightness Races in Orbit Oct 28 '13 at 10:46
  • Thanks for the response, but to be honest I'm just using whatever co-ordinates Google maps provides for a given point. It's a very very simple website, and the co-ordinates are really only being used to give a simple distance measurement, and then be fed back into the Google maps API to display a location. However, I was unaware that there were different GPS standards, and did not realize that higher accuracy could be achieved. I will keep it in mind for next time, but so far the current approximation appears to be working for my purposes. – user2922572 Oct 29 '13 at 11:58
  • There is one GPS standard. GPS works on timing. Timing from multiple GPS satellites is correlated by your device to produce a position. There are many ways to notate position on the Earth, and many ways to approximate the distance between two points on the Earth. It's not a GPS thing but a math & physics thing. – Lightness Races in Orbit Oct 29 '13 at 15:27

1 Answers1

0

you could use the distance formula as a measure of closeness: d = sqrt((ax-bx)^2 + (ay-by)^2)

where (ax, ay) and (bx, by) are the coordinates of landmark and parking. you can also remove the sqrt() function altogether since you will just be comparing the distances for other coordinate pairs.

aaa
  • 489
  • 5
  • 13
  • check this one: http://stackoverflow.com/questions/9096548/what-formula-to-use-to-calculate-a-small-distance – aaa Oct 28 '13 at 07:27
  • Excellent, thankyou very much for the advice and the great resource. This has helped me greatly. I am now able to calculate the distance between all of my GPS markers. Now I just need to be able to echo the details of the parking with the smallest distance to the screen, but I suppose that's a question for another thread. Thankyou again. – user2922572 Oct 28 '13 at 07:43
  • Note that this is only a vague approximation; see my comment on the question. – Lightness Races in Orbit Oct 28 '13 at 10:46