Skip to content
Advertisement

PHP to Javascript Arrays and GPS locations

I’m making a script that will hopefully be mainly PHP so it doesn’t require Javascript later on, but right now I’m stuck on a few things.

  1. What is the best way to store GPS locations, and then compare them? I could use to store them in a database (currently using MySQL), and then find people nearby with some code, but I fear this would quite intensive, especially if a lot of values are in the database. This should be executed on the server, I’m currently using PHP right now.

  2. How can I get this data, and then represent it in Google Maps? I’ve currently got my code working when I have already put in the data, but I would like to get this data from a database. Would it be asking too much of the user to place say 100 markers on a single Google Maps view to represent all people around the world? Or should I just stick with people within a certain area? My current code is:

    JavaScript

    Each ‘type’ displays a different image, so I need to pull the type, lat and long from a database and put them into this Javascript Array.

I know there’s a few questions thrown in there, I’m new to this side of javascript and Maps 🙂

Advertisement

Answer

1. Your first question

I had to solve something like this last week and I did it like this.
Let’s say I have a list of some offices in MySQL database with their GPS coordinates (gps_lat, gps_lon) and I want to sort them by their distance to my current location ($latitude, $longtitude) in km.

JavaScript

Maybe check this link Deriving the Haversine Formula, it helped me a lot. I know this looks weird in SQL. The $varA is just one part of the formula that repeats twice. Original formula in the link above looks like this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement