Extract only the latitude and longitude information of any address with the Yahoo! Geocoder API.
geo.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import sys, codecs
def get_Coordinates(location_name):
payload = {
"appid": "******************************",
"output":"json"
}
payload["query"] = location_name
url = "http://geo.search.olp.yahooapis.jp/OpenLocalPlatform/V1/geoCoder"
r = requests.get(url, params=payload)
res = r.json()
for i in res["Feature"]:
print i["Geometry"]["Coordinates"]
if __name__ == "__main__":
get_Coordinates(u"4-2-8 Shibakoen, Minato-ku, Tokyo")
Select the data returned by json
for i in res["Feature"]:
print i["Geometry"]["Coordinates"]
It is specified by. For example, if you want to read the data contained in ["Feature"]
for i in res["Feature"]:
print i["Geometry"]["Coordinates"]
print i["Property"]["Address"]
You can add something like this. Don't forget the Yahoo copyright notation if you use it somewhere.
Recommended Posts