Skip to content

Instantly share code, notes, and snippets.

@moltak
Last active August 29, 2015 14:10
Show Gist options
  • Save moltak/55a576d0df7f386d9fe6 to your computer and use it in GitHub Desktop.
Save moltak/55a576d0df7f386d9fe6 to your computer and use it in GitHub Desktop.
gps reverse geo coding(daum api)
#!/bin/bash
import simplejson, urllib2
BASE_URL = "http://apis.daum.net/local/geo/coord2addr?" \
"apikey=DAUM_LOCAL_DEMO_APIKEY&latitude={0}&longitude={1}&output=json&inputCoordSystem=WGS84"
def get_address(lat, lng):
global BASE_URL
try:
url = str.format(BASE_URL, lat, lng)
data = urllib2.urlopen(url)
result = simplejson.load(data)
# print str.format("lat:{0}, lng:{1}", lat, lng)
print result['fullName']
# print result
except urllib2.HTTPError, e:
print "HTTP error: %d" % e.code
except urllib2.URLError, e:
print "Network error: %s" % e.reason.args[1]
def calc_region(lat1, lng1, lat2, lng2, max_count):
diff_lat = (lat2 - lat1) / max_count
diff_lng = (lng2 - lng1) / max_count
temp_lat = lat1
temp_lng = lng1
print str.format("lat-raise({0}), lng-raise({1})", diff_lat, diff_lng)
while temp_lat <= lat2:
while temp_lng <= lng2:
get_address(temp_lat, temp_lng)
temp_lng = temp_lng + diff_lng
temp_lat = temp_lat + diff_lat
temp_lng = lng1
print str.format("lat-end({0}), lng-end({1})", temp_lat, temp_lng)
calc_region(33.491496, 126.520109, 33.520695, 126.543111, 10)
print 'end'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment