views:

31

answers:

1

So.. I have 10 latitude/longitude values in a database.

Using the V3 JS API i plot these on a map.

I then have an 11th point which is 'users current location'

I want to find the distance between the user location and each of the other points.

I have created a javascript which does this - essentially, it gets the lat/long, plots the markers etc. Then with a PHP foreach loop, i loop through the lat/long pairs, and output the javascript which gets these values.

Now.. I myself do not really understand how this works.. i followed tutorials :) But it does. It uses the directionservices() function. None the less, I feel that it is safe to assume that this method must be somewhat inefficient.

Does anyone know if this is a good approach?efficient approach? what alternatives there arE?

Many Thanks

A: 

In which database do you store the lat lng values? If your database is spatially enabled as PostGis is you can use build in database functions that i think is fast and efficient.

Then maybe you can find also a way for cashing precalculated numbers(i.e. distances) and improve the speed additionally.

Argiropoulos Stavros
I am using MySQL. I have a php function which calculates straight line distances, but i want exact driving distances which seemingly only google maps can provide. Caching is not a possibility as there is essentially an infinite number of combinations...
Thomas Clowes
Hmmm...You can make ajax requests to the server to take the lat lng values with lets say json
Argiropoulos Stavros