Jump to content

Displaying results based on location


ki

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.