Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

Most sites I know of that use geolocation cause the browser to show a dialog asking the user permission to gather location info. This is like it can be seen here:

http://html5demos.com/geo and the way it works with Google Maps.

But Twitter seems to be able to do it another way. From twitter.com, when you compose a Tweet, you can click a little button, and it will add your location to your Tweet.

But in the case of the twitter implementation, there is no user interruption.

How is this done?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

The twitter website seems to do a XHR request to https://twitter.com/account/geo_location.json which returns the user's current location as a json object. Since location detail is about city-level, I'd guess they are using the client's IP address to locate them using a IP-Locations database.

There are numerous commercial and free API's available to match IP addresses to approximate locations, such as http://ipinfodb.com/ip_location_api.php, if you want to do something similar.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.