tags:

views:

54

answers:

4

Basically, I want to display local events to people on a page. So if you were from California you would have different things than someone from Florida. I am going to be using php for the rest of the project so php is a must.

I would prefer to get the data without having to ask the user for additional information. IF I have to ask for additional information, I would want to use a zipcode than I would save that zipcode to a database with their ip so I didn't have to ask again.

+1  A: 

How will you know the location of the person?

For example, you can't go by the ISP, as their ISP address may be in a different state than the user.

If they have to log in then you can know where they were when they logged in, but what if the are on a trip and so staying elsewhere, now your information is wrong.

That would be the first challenge.

Depending on how fine-grained you are trying to get will determine what your database looks like. For example, while I am going down a street, if I am using a mobile device, will you be able to use my GPS data to determine what gluten-free restaurant is close to me? Or is it based on a city or metropolitan area?

Are you using GPS data?

How will you get the local events to update your application?

There is a great deal of information left unanswered to be able to really give you a good answer.

James Black
What do most sites do? I know I go to certain sites and it knows where I am coming from.
Joe
I expect that most of them get the address of your ISP, as that will tend to be close to where you are, unless you live in a rural region or use a satellite provider.
James Black
+3  A: 

I would imagine the GEO IP functions would get you 90% of the way there, if not all the way.

Peter Bailey
+1  A: 

Are you trying to guess the visitor's location? If that is what you want, see the PHP GeoIP extension or MaxMind GeoIP api. They both use the same database and offer free and paid databases.

One problem with this method is that the IP address does not guarantee an accurate location. It is often a good starting point though. You should make it easy for the visitor to correct their location.

A potentially more accurate method is to use the HTML5 geolocation api, but this is experimental and only supported in the latest browsers. Even with browser support, the site visitor needs hardware capable of finding their location or a plugin that allows them to set their own location. If you go this route you should have a fall back based on the GeoIP result.

mcrumley
A: 

You could look up their IP address in a geolocation database like other people have mentioned, and as everyone has pointed out, it's not foolproof but it should work most of the time.

You could also take a look at using Firefox's location-aware browsing, which again isn't foolproof -- yet it does accurately pinpoint my very house when I use it. Of course, this would only work for Firefox 3.0+ users, and only after they click the "accept" button, so it's obviously not without issues.

Whichever way you choose to go, just make sure there's an override somewhere! Your method might work 99% of the time, but if I'm in the 1% of people who are never shown the right information, that'd be really really annoying!

nickf