Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6926419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:54:57+00:00 2026-05-27T10:54:57+00:00

I want to create a store locator with Google Maps. I have a database

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:54:58+00:00Added an answer on May 27, 2026 at 10:54 am

    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.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <style>
    #map_canvas{width:500px;height:500px;}
    </style>
    </head>
    
    <body>
    <div id="map_canvas"></div>
    <script>
    <?php
    //you'll first need to connect to your db
    //you also have to edit the lat/lng in your SELECT statement to be that of your objective
    $result = mysql_query("SELECT  latitudine, longitudine, 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");
    $c=0;
    echo "var data=[";
    while($markers=mysql_fetch_array($result)){
        if($c>0){echo ",";}
        echo "['".$markers[0]."','".$markers[1]."','".$markers[2]."','".$markers[3]."','".$markers[4]."','".$markers[5]."','".$markers[6]."'"."]";
        $c++;
    }
    echo "];";
    ?>
        //var data=[['45','-73','home','poz1','desc1','link1'],['43','-75','work','poz2','desc2','link2']];
        var places=new Array();
        var map;
        var MyInfoWindow = new google.maps.InfoWindow({content: 'Loading...'});
        var bounds = new google.maps.LatLngBounds();
        var myOptions = {
            zoom: 9,
            mapTypeControl: false,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);
        for(i=0;i<data.length;i++){
            var point=new google.maps.LatLng(data[i][0],data[i][1]);
            var a = new google.maps.Marker({position: point,map: map, icon:'someHotelIcon.png'});
            a.lat=data[i][0];
            a.lng=data[i][1];
            a.nume=data[i][2];
            a.poze=data[i][3];
            a.desc=data[i][4];
            a.url=data[i][5];
            places.push(a);
        }
        for(i=0;i<places.length;i++){
            var point2=new google.maps.LatLng(places[i].lat,places[i].lng);
            bounds.extend(point2);
        }
        map.fitBounds(bounds);
        var objLoc=new google.maps.LatLng(45.515038,26.366935);
        var objectiveMarker = new google.maps.Marker({position: objLoc,map: map, icon:'objectiveIcon.png'});    //---------------Marker for objective
        for (var i = 0; i < places.length; i++) {
            var marker = places[i];
            google.maps.event.addListener(marker, 'click', function () {
            MyInfoWindow.setContent(this.nume+'<br/>'+this.desc+'<br/><a href=\"'+this.url+'\">link</a>');
            MyInfoWindow.open(map, this);
            });
        }
    </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to store the distance between different locations in a table. CREATE TABLE
I want to create a model to store comments related to articles. I have
I want to create an editor and store formatted text in database. I want
I have two paid apps on app store. I want to create one app
I want to create a model that doesn't map to a database table. Instead,
My User object that I want to create and store in the datastore has
I want to create an ini file to store some settings for my application.
I have a stored procedure in which i want to create a user defined
I want to store data in string form to MySQL. I have created the
i want create image animation , i have 50 images with png format now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.