7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python で目的地の地図をGoogle Mapの.htmlとして作成

Last updated at Posted at 2018-04-28

現在使用できない可能性が大です。

ブラウザでGoogleMapを使用していると、真っ白になり地図が表示されないことがありググっていたら、Googlemapのが有料でAPIキーが入力されないと表示されないように変更になったためのようなことが書いていました。
試しに実行しましたが、5回程度実行しましたがダメでした。

実行した環境

Ubuntu Stdio 17.10
Python 3.6.3

参考

https://j138i.com/python-folium-sample0/
python:foliumで地図に目印を付てみる

インストール

pip3 install pygeocoder
pip3 install folium

使い方

./map.py 目的地の名称
目的地の名称はGoogleマップで検索出来る名称

例.
./map.py ユニバーサルスタジオジャパン

map.pyのあるフォルダにユニバーサルスタジオジャパン.htmlが作成される。

map.py
# !/usr/bin/python3
# coding: UTF-8

from pygeocoder import Geocoder
import folium
import sys

args = sys.argv
argc = len(args) # 引数の個数

if (argc != 2):   # 引数がない場合
    print ('./map.py 目的地の名称')
    quit()

try:
    area_name = args[1]
    place= Geocoder.geocode(area_name)
    loc = place[0].coordinates
    map_obj =folium.Map(location=loc,zoom_start=15)

    folium.Marker(loc,popup=str(area_name),
    icon=folium.Icon(color='blue',icon='info-sign')
    ).add_to(map_obj)

    map_obj.save(args[1] + ".html")
except:
    quit()

住所追加版

map_address.py
# !/usr/bin/python3
# coding: UTF-8

from pygeocoder import Geocoder
import folium
import sys

args = sys.argv
argc = len(args) # 引数の個数

if (argc != 2):   # 引数がない場合
    print ('./map_address.py 目的地の名称')
    quit()

area_name = args[1]

def map():
    try:
        place= Geocoder.geocode(area_name)
        loc = place[0].coordinates
        map_obj =folium.Map(location=loc,zoom_start=15)

        folium.Marker(loc,popup=str(area_name),
        icon=folium.Icon(color='blue',icon='info-sign')
        ).add_to(map_obj)

        map_obj.save(args[1] + ".html")
    except:
        quit()

def address():
    try:
        results = Geocoder.geocode(area_name)
        print(results.coordinates)
        result = Geocoder.reverse_geocode(*results.coordinates, language="ja")
        print(result)
    except:
        quit()

map()
address()

image.png

image.png

7
7
0

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
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?