LoginSignup
13
9

More than 5 years have passed since last update.

YOLP:Yahoo!ジオコーダAPIで緯度経度を抜き出す。

Posted at

Yahoo!ジオコーダ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")

jsonで返るデータの選択を

    for i in res["Feature"]:
        print i["Geometry"]["Coordinates"]

で指定している。例えばこれに["Feature"]に含まれるデータを読みたい場合は

    for i in res["Feature"]:
        print i["Geometry"]["Coordinates"]
        print i["Property"]["Address"]

こんな感じで書き足せばいい。
どこかで使用する場合はYahooコピーライト表記を忘れずに。

13
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
9