I want to create a store locator with Google Maps.
I have a database with a table of TOURISTIC OBJECTS (with their coordinates) and a table of HOTELS (also with their coordinates).
I want the user to have the possibility, after he loads the page of the Tower of London, let’s say, to see what hotels are near the object within a 10-kilometer radius and display the results on Google Maps with markers.
So far, I’ve only managed to fetch the hotels in a 10-kilometer range from the database with the haversin formula and display them as text:
$result = mysql_query("SELECT nume, poze, descriere, link, (
(
ACOS( SIN( 45.515038 * PI( ) /180 ) * SIN( latitudine * PI( ) /180 ) +
COS( 45.515038 * PI( ) /180 ) * COS( latitudine * PI( ) /180 ) *
COS( ( 25.366935 - longitudine ) * PI( ) /180 )
) *180 / PI( )
) *60 * 1.1515 * 1.609344
) AS distance
FROM `unitati`
HAVING distance <= '10'
ORDER BY distance ASC
LIMIT 0 , 30");
How can I display them as markers on the map?
I found this and I thought it could help me: http://code.google.com/intl/ro-RO/apis/maps/articles/phpsqlsearch.html, but it has a different logic: the user types in the address.
This example takes your query (and you’ll need to edit the 45.515038 and 25.366935 with the lat/lng for each objective) and outputs it as a JS array of arrays (you could make it more formal JSON if you like)
It then loops through that array, making markers for each and placing them on a map. Finally, it adds a click listener to each so that it’ll display relevant information.