ɹɐqʞɐ zoɹǝɟ
ɹɐqʞɐ zoɹǝɟ

Reputation: 4370

Python: Django: How can i find the users Lattitude and Longitude so that i can show the users location?

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.

Upvotes: 1

Views: 1806

Answers (3)

Shubham Chaudhary
Shubham Chaudhary

Reputation: 50993

IP API is a very nice way to do it. More accurate than others mentioned here. enter image description here

Upvotes: 0

Javier Vieira
Javier Vieira

Reputation: 2140

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.

Upvotes: 2

Trausti Thor
Trausti Thor

Reputation: 3774

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.

Upvotes: 1

Related Questions