I am trying to locate a user through his/her IP address and then show them in a google map. what would be the best approach for this purpose. Or is there any other way to get the user lat/long and show em in a google map instead of IP address.
Your question is actually 2 questions. The first part is getting lat, lng from an ip address. AFAIK, google maps api doesnt provide for IP based geolocation. Therefore to show the IP address on a google map, you must first get the geographic location (either as an address, or as lat, lng). There are various paid and unpaid APIs on the web that allow you to do this, and django itself comes with a utility for this. The docs are here. Your use case would be implemented as:
from django.contrib.gis.utils import GeoIP
g = GeoIP()
lat,lng = g.lat_lon(user_ip)
or
address = g.city(user_ip)
NOTE: This utility, or one of the many free IP based geolocation APIs might not be VERY accurate.
As for the second part, to show this location on a google map, you could check out this application:
http://code.google.com/p/django-googlemap/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With