views:

648

answers:

5

I am currently working on a show listing website. I am going to display show information by location for the user sorted in a variety of different ways.

I know I could ask the user where they are located when they first sign into the site, but I've seem to notice that many sites have this capability built-in to detect location automatically? (Ex. see Last.fm "Events: Concert Listings in your area").

Anyone have any idea how they do this? I'm currently building my website in Rails.

A: 

you google maps api to geo-locate user. they have a function for that.

dusoft
How about you show him?
Geoffrey Chetwood
yeah. a little-bit-more-info slash links would help.
CodingWithoutComments
he can google it. i am providing a way to go, not the target. that's what stack overflow is for.
dusoft
no, i'm pretty sure i'm looking for an answer to the question i asked. if someone google's this question, then they get this page that tells them to google for the answer, well, then what then?
CodingWithoutComments
@dusoft: Actually, the idea of stackoverflow is to have the info here, not to tell people to google it.
Geoffrey Chetwood
yeah, vote me down for being helpful. if somebody is unable to google things, then it's their problem, not mine. i told him to google google maps api :-)
dusoft
@dusoft: You chose to make an answer that is not useful. Not anyone else. For an example of what this community expects: http://stackoverflow.com/questions/596921/how-do-i-automatically-find-a-users-location/596951#596951
Geoffrey Chetwood
i choose to provide an answer i know is correct and working. i don't care what do you expect me to provide, so go enjoy some real life.
dusoft
@dusoft: Ok, that is fine, but don't be surprised when you get negative feedback.
Geoffrey Chetwood
A: 

They usually do using IP resolution by IP tables. ip2nation might give some idea

Can Erten
+5  A: 

Here's a link to the documentation on the relevant Google Maps API:

http://code.google.com/apis/ajax/documentation/#ClientLocation

It shows an example of how to use it:

/**
 * Set the currentState_ and currentCountry_ properties based on the client's
 * current location (when available and in the US), or to the defaults.
 */
InTheNews.prototype.setDefaultLocation_ = function() {
  this.currentState_ = this.options_.startingState;
  if (google.loader.ClientLocation &&
      google.loader.ClientLocation.address.country_code == "US" &&
      google.loader.ClientLocation.address.region) {

    // geo locate was successful and user is in the United States. range
    // check the region so that we can safely use it when selecting a
    // state level polygon overlay
    var state = google.loader.ClientLocation.address.region.toUpperCase();
    if (InTheNews.stateNames[state]) {
      this.currentState_ = state;
    }
  }
  this.currentCountry_ = "US";
}

And tells you what you will get from it:

When populated, the google.loader.ClientLocation object is populated with the following metro-level granularity properties:

  • ClientLocation.latitude — supplies the low resolution latitude associated with the client's IP address

  • ClientLocation.longitude — supplies the low resolution longitude associated with the client's IP address

  • ClientLocation.address.city — supplies the name of the city associated with the client's IP address

  • ClientLocation.address.country — supplies the name of the country associated with the client's IP address

  • ClientLocation.address.country_code — supplies the name of the ISO 3166-1 country code associated with the client's IP address

  • ClientLocation.address.region — supplies the country specific region name associated with the client's IP address

runako
this is cool thanks.
CodingWithoutComments
I'm sort of new to the community, so this may be off base, but how does including a snippet from the page materially add to the answer? He's still going to have to click the link to use the API, isn't he?
runako
@runako: The idea is for SO to be a wiki full of information. So having the link is a great start, but giving a bunch more information to give someone a good head start is even better.
Geoffrey Chetwood
@runako - What if the page moves, or gets deleted?
ceejayoz
In that case, the docs posted above are most likely deprecated as well.
runako
@runako: And then this wiki can be edited. I recommend you read through the FAQ for more info on why we prefer this on SO if you want more info.
Geoffrey Chetwood
runako
FAQ: http://stackoverflow.com/faq
Geoffrey Chetwood
Blog: http://blog.stackoverflow.com
Geoffrey Chetwood
Also -- might want to add something to the FAQ concerning how to handle mirroring docs on official vendor API pages (i.e. developer.apple.com) vs. docs on 3rd party sites (i.e. joesblog.com). I'd argue that you don't really want to try to mirror a canonical source like the former.
runako
Geoffrey Chetwood
A: 

You might like to look at MaxMind's GeoLite soluton for IP location. An open source solution.

Rob Wells
sweet. thanks alot.
CodingWithoutComments
A: 

There is a new way , infact its the better way to find geo-location, because Browser will natively support W3C api for geolocation... You should checkout GeoMereLaal

Green Anthony