1

I am working on a project which requires my current location's exact lat-long. I tried to run the code using Google Maps API as well as http://freegeoip.net/json on windows 7 machine, but nothing seems to take 'My current location' as an input and output the exact lat-long.

Can someone please help?

Thanks, Sanket.

Sanket
  • 119
  • 1
  • 6
  • 15
  • 3
    What do you mean by taking "my current location" as input? What's wrong with the api you posted? Also there is no way to obtain your **exact** lat-long, but apis like that will usually give you a reasonable estimate. You'd need a GPS for anything more specific... – Shadow Nov 02 '17 at 03:26
  • 1
    Tell us what you you attempted to do and then can help. Please refer to how to create a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – skrubber Nov 02 '17 at 03:27
  • You need to provide your IP address at the end of `http://freegeoip.net/json/[ip_address]` – yash Nov 02 '17 at 03:28
  • Shadow - Yes I am looking for approx lat-long values. Apologies for the "exact" keyword. sharatpc - I am attempting to match my current location to some pre-defined location (using approx lat-longs) and if it is a match, send an arrival SMS. For that, I need, lat-longs of my current location so that I can compare it with my office location. yklsga - Yes I tried providing my IP in an URL - 'http://freegeoip.net/json/1.2.3.4' but it is returning no value. – Sanket Nov 02 '17 at 03:52

1 Answers1

5

This is very simple. You can try this one

first, you need to install the geocoder module

pip install geocoder

Then you can try this one

import geocoder
myloc = geocoder.ip('me')
print(myloc.latlng)
mhhabib
  • 2,975
  • 1
  • 15
  • 29
Balaraju M
  • 473
  • 1
  • 3
  • 14
  • I am attempting to match my current location to my office location and if they match, send an arrival SMS. Sitting at my office now, when I run above code, there's a mismatch between lat-longs I get from https://mynasadata.larc.nasa.gov/latitudelongitude-finder/ and the code. Any approx value would work. – Sanket Nov 02 '17 at 03:55
  • Does geocoder provides the exact current location or it is IP based? – pmatos Feb 24 '20 at 10:55
  • 1
    This wasn't helpful, unfortunately, as the returned location is broad (in my case - the municipality of where I live), and not my own exact lat/long location. – Yoav Vollansky Sep 10 '21 at 21:05