Created
July 10, 2012 08:57
-
-
Save y-ogi/3082129 to your computer and use it in GitHub Desktop.
住所から緯度、経度を取得する
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import urllib | |
from xml.etree.ElementTree import parse | |
def adr2geo(adr): | |
api = "http://www.geocoding.jp/api/?v=1.1&q=%s" % (urllib.quote(adr.encode('utf-8'))) | |
xml = parse(urllib.urlopen(api)).getroot() | |
lat = xml.find('coordinate/lat').text | |
lng = xml.find('coordinate/lng').text | |
return (float(lat), float(lng)) | |
def main(): | |
print adr2geo(u'東京都千代田区千代田1番1号') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment