-1

I am new in PHP and i would like to search cities that are located within a certain number of miles?

For. e.g.

When people sign up, they will register will their physical address. When someone is searching for a member they will search by city and Search functionality will be based on distance away.

My Html Code

<form method="get" id="sul-searchform" action="" ?>">
        <div class="frmSearch">
            <input type="text" id="search-box" name="as"  placeholder="City, state or zip" />
            <label>Select a distance in miles:</label>
                    <select name="distance">
                    <option>5</option>
                    <option>10</option>
                    <option>25</option>
                    <option>50</option>
                    <option>100</option>
            <input type="submit" class="submit" name="submit" id="sul-searchsubmit" value="Search Member" />
            <div id="suggesstion-box"></div>
        </div>
    </form>

I want same like this click here

i do not have any idea how to do this , does anyone know about it then please share me code with steps by steps?

samir
  • 137
  • 2
  • 10

1 Answers1

1

There is one way you can do this.

1 - Get the geolocation of the user by using GeoLocation API of the web browser.

2 - After getting the geolocation you can use that info with Google Map's Reverse geocoding API to get the CITY name details where the user is currently present.

3 - Then map the city details with the respective user in a table. So that, whenever you need all members present in any particular city you can directly make a query to your DB to get all those members details.

Ref for Geolocation API -

https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation

Ref for Reverse geocoding API -

https://developers.google.com/maps/documentation/geocoding/start?csw=1#ReverseGeocoding

Ex of Reverse geocoding API:

http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true

Hope it'll help you.

Suresh
  • 5,687
  • 12
  • 51
  • 80
  • I want location data from database. – samir May 02 '17 at 08:48
  • For that at the time of Signup only get those CITY details & store in your DB. Then whenever u require searching members from any city... u can directly search from DB. – Suresh May 02 '17 at 08:52
  • can you please share me code how cities that are located within a certain number of miles? – samir May 02 '17 at 09:55
  • I don't think so, there is any such api exist. But, if you've 2 geo-points then by using some calculations you can fig. out what's the distance between them. So, if you've all geo-coordinates of cities in your DB then by comparing those coordinates with any specific geo-coordinates you can able to know what exact distance between those two cities. Ref - http://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula – Suresh May 02 '17 at 10:04
  • i am not creating any api, i just want to fetch record from database that given to me nearest value. – samir May 02 '17 at 10:08
  • Do you've all cities geo-coordinates in your DB? I believe you don't have. If you've then you can directly use that Ref- code to know what exactly the distance between them. But, if you don't have those cities geo coordinates then you've to extract those coordinates by using some previous mention technique. – Suresh May 02 '17 at 10:13