ki Posted September 23, 2014 Share Posted September 23, 2014 I'm trying to pull results from a database based on where the user is located based upon the variables $usr_lat & $usr_lng, and search for by a radius of x amount of miles/km (need to make it optional). I can't seem to find exactly what I'm looking for on google so I thought I'd asked here. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/291230-displaying-results-based-on-location/ Share on other sites More sharing options...
sKunKbad Posted September 23, 2014 Share Posted September 23, 2014 First, you can turn an IP address into geo coordinates with Google's Geocode API: https://developers.google.com/maps/documentation/geocoding/ Next, take those geo coordinates and query your database using a sophisticated query based on the following info: http://www.notaires.fr/sites/default/files/geo_searchjkkjkj_0.pdf That should get you started. I use this to query for properties that are within a certain radius. It works well, and we turned it into a stored procedure to make it run a little faster. Unfortunately, I'm not allowed to share that code with you. Quote Link to comment https://forums.phpfreaks.com/topic/291230-displaying-results-based-on-location/#findComment-1491851 Share on other sites More sharing options...
mogosselin Posted September 23, 2014 Share Posted September 23, 2014 For the Google API, I think that for the free version you need to display Google Map on your page to query their API with that kind of request. But, you can also get it with HTML5: http://diveintohtml5.info/geolocation.html Which will probably require some Ajax on your part because it's on the client side. And, the user will need to approve the geolocation request (depending on his settings). Quote Link to comment https://forums.phpfreaks.com/topic/291230-displaying-results-based-on-location/#findComment-1491862 Share on other sites More sharing options...
sKunKbad Posted September 23, 2014 Share Posted September 23, 2014 You know what, I am totally wrong. We aren't using the Google API for converting IP addresses into a location. We are using an IP2LOCATION database. http://www.ip2location.com/ You do have to pay for this though. The HTML5 way being free, it's certainly the way to go. I've noticed that the IP2LOCATION results can be way off too, so it may not be worth paying for. Quote Link to comment https://forums.phpfreaks.com/topic/291230-displaying-results-based-on-location/#findComment-1491915 Share on other sites More sharing options...
ki Posted September 24, 2014 Author Share Posted September 24, 2014 I already have the method for getting the coordinates. I just need help with the formula I explained above. Quote Link to comment https://forums.phpfreaks.com/topic/291230-displaying-results-based-on-location/#findComment-1491922 Share on other sites More sharing options...
CroNiX Posted September 24, 2014 Share Posted September 24, 2014 I already have the method for getting the coordinates. I just need help with the formula I explained above. Did you read the first reply from Skunkbad? The 2nd link contains what you're after. Quote Link to comment https://forums.phpfreaks.com/topic/291230-displaying-results-based-on-location/#findComment-1491923 Share on other sites More sharing options...
superromia Posted December 16, 2014 Share Posted December 16, 2014 Try this, https://lite.ip2location.com/database-ip-countryIts free to use and provide you the country of the user based on the IP address. A variety of APIs is also provided. Easy to implement. Quote Link to comment https://forums.phpfreaks.com/topic/291230-displaying-results-based-on-location/#findComment-1499710 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.