Created
August 16, 2015 08:54
-
-
Save alpha-beta-soup/e674a4e61cd0432ee429 to your computer and use it in GitHub Desktop.
Zoom to your current location in QGIS (assuming EPSG 4326)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qgis.utils | |
import pycurl | |
import StringIO | |
import json | |
buffer = StringIO.StringIO() | |
c = pycurl.Curl() | |
c.setopt(c.URL, 'http://ipinfo.io/') | |
c.setopt(c.WRITEDATA, buffer) | |
c.perform() | |
c.close() | |
body = buffer.getvalue() | |
lat, lon = [float(coord) for coord in json.loads(body)['loc'].split(',')] | |
mc = qgis.utils.iface.mapCanvas() | |
scale = 0.01 | |
rect = QgsRectangle(lon-scale,lat-scale,lon+scale,lat+scale) | |
mc.setExtent(rect) | |
mc.refresh() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IP address geolocation is not an exact science.