Нашел решение через внешний API
Тут способ получения координат, остальное мелочи.
Вдруг кому понадобится, как мне.
import urllib, json
PRIVATE_IPS_PREFIX = ('10.', '172.', '192.',)
def get_client_ip(request):
remote_address = request.META.get('REMOTE_ADDR')
ip = remote_address
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
proxies = x_forwarded_for.split(',')
while (len(proxies) > 0 and
proxies[0].startswith(PRIVATE_IPS_PREFIX)):
proxies.pop(0)
if len(proxies) > 0:
ip = proxies[0]
return ip
def get_res(request):
client_ip= get_client_ip(request)
if client_ip is None:
client_ip = "0.0.0.0"
ip_address = '106.220.90.88'
try:
url = 'https://api.ipfind.com/?ip=' + client_ip
response = urllib.request.urlopen(url)
data1 = json.loads(response.read())
longitude = data1["longitude"]
latitude = data1["latitude"]
except:
url = 'https://api.ipfind.com/?ip=' + ip_address
response = urllib.request.urlopen(url)
data1 = json.loads(response.read())
longitude = data1["longitude"]
latitude = data1["latitude"]