P
P
Ping Wins2019-06-05 14:34:12
Python
Ping Wins, 2019-06-05 14:34:12

Is it possible to know the location of a person in PYTHON?

There is a small task: to find out the user's coordinates using python3 (latitude and longitude), I rummaged through the Internet and could not find it (probably I was looking badly).

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexander, 2019-06-05
@PingWins

Since geolocation is needed, it means a wearable device, since a wearable device means an android, since an android means QPython + SL4A:

# import needed modules
import android
import time
import sys, select, os #for loop exit

#Initiate android-module
droid = android.Android()

#notify me
droid.makeToast("fetching GPS data")

print("start gps-sensor...")
droid.startLocating()

while True:
    #exit loop hook
    if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
        line = input()
        print("exit endless loop...")
        break

    #wait for location-event
    event = droid.eventWaitFor('location',10000).result
    if event['name'] == "location":
        try:
            #try to get gps location data
            timestamp = repr(event['data']['gps']['time'])
            longitude = repr(event['data']['gps']['longitude'])
            latitude = repr(event['data']['gps']['latitude'])
            altitude = repr(event['data']['gps']['altitude'])
            speed = repr(event['data']['gps']['speed'])
            accuracy = repr(event['data']['gps']['accuracy'])
            loctype = "gps"
        except KeyError:
            #if no gps data, get the network location instead (inaccurate)
            timestamp = repr(event['data']['network']['time'])
            longitude = repr(event['data']['network']['longitude'])
            latitude = repr(event['data']['network']['latitude'])
            altitude = repr(event['data']['network']['altitude'])
            speed = repr(event['data']['network']['speed'])
            accuracy = repr(event['data']['network']['accuracy'])
            loctype = "net"

        data = loctype + ";" + timestamp + ";" + longitude + ";" + latitude + ";" + altitude + ";" + speed + ";" + accuracy

    print(data) #logging
    time.sleep(5) #wait for 5 seconds

print("stop gps-sensor...")
droid.stopLocating()

V
Vladimir Kuts, 2019-06-05
@fox_12

Maybe.
1. Take the documentation for your device, in terms of accessing GPS or where you are going to read the location data.
2. Read how to get the necessary data from it.
3. You receive.

S
ScratchBoom, 2019-06-05
@ScratchBoom

If there is no GPS, you can determine the approximate location by IP
https://www.ip2location.com/developers/python
www.ip2geo.net/ip2location/lookup.php

E
Evgeny Nikolaev, 2019-06-05
@nikolaevevge

If you need to determine by IP as an option, you can use ipGeoBase blog.ivru.net/?id=82

M
Mrkliner, 2021-07-26
@Mrkliner

use the geocoder library (the location is determined there by ip)
I left the code of my program below

import geocoder as g
import os as s
import time as t
while True:
  s.system ('color B')
  print ('Введите айпи или введите (Мой айпи) для просмотра вашей гео-локации')
  ipi = input ('>>')
  if ipi == 'Мой айпи':
    print (g.ip('me'))
    geo = g.ip('me')
  else:
    geo = g.ip(ipi)
    print ('Город, страна:')
    print (g.ip(ipi))
  print ('\nШирота и долгота:')
  print (geo.latlng)
  s.system('pause')
  s.system ('cls')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question