Is there any possibility to find the user's location in django. I mean is there any way to get the latitude and longitude and then the location.
Asked
Active
Viewed 1,522 times
1
-
1See [What python libraries can tell me approximate location and timezone given an IP address?](http://stackoverflow.com/questions/2543018/what-python-libraries-can-tell-me-approximate-location-and-timezone-given-an-ip) – Shawn Chin Dec 20 '12 at 12:29
3 Answers
2
I don't Believe Django can do that directly, what you can do with Django is request the IP of the user, and the using a free webservice from outside, request the latitude and longitude and then the location
for example... easy python code:
IP_URL = "http://api.hostip.info/?ip="
def get_coords(ip):
url = IP_URL + ip
respond = None
try:
respond = urlib2.urlopen(url).read()
execept URLError:
return
if respond:
#Parse de returned XML Here, you can use MiniDom
By the way api.hostip.info work well if the user is in the USA. Outside not so well... but you get the idea.
Javier Vieira
- 2,080
- 20
- 23
1
Either you get yourself some geo ip table to look up or you use the location library in html5.
Like here : http://html5demos.com/geo
This demo actually shows you a map, but the javascript query actually gives you latitude and longitude.
Trausti Thor
- 3,604
- 30
- 41
0
IP API is a very nice way to do it. More accurate than others mentioned here.
Shubham Chaudhary
- 42,546
- 9
- 73
- 80