0

Hi I'm currently trying to get GPS coordinates of a user in python. I have tried various methods but they are a little inaccurate for what I want to do.

The most accurate method I have found is the W3 schools method as follows:

<script>
var lat,lon

function getLocation() 
{
  if (navigator.geolocation) 
  {
    navigator.geolocation.getCurrentPosition(showPosition);
  } 
}

function showPosition(position) 
{
  lat= position.coords.latitude  
  lon= position.coords.longitude
  cords='{"lat":'+lat+',"lon":'+lon+'}'
}

getLocation()

</script>

I want to echo var cords in a PHP file, this way it will allow the source code to be just $cords and I could use the following python function

def grabGPS(): 
    send_url='http://127.0.0.1:8080/urlTest/gps.php'
    geoRequest=requests.get(send_url)
    geoData=json.loads(geoRequest.text)
    lat = geoData['lat']
    lon = geoData['lon']
    print(lat)
    print(lon) 

Thanks for any help that can be rendered

Revin
  • 31
  • 3

0 Answers0