oss-gate / workshop

OSSの開発に未参加または参加したことはあるけどまだ自信がない人を後押しするワークショップ用のリポジトリー
124 stars 547 forks source link

OSS Gate Workshop: Tokyo: 2017-11-25: hyuraku: google-maps-services-python: Work log #670

Closed hyuraku closed 6 years ago

hyuraku commented 6 years ago

This is a work log of a "OSS Gate workshop". "OSS Gate workshop" is an activity to increase OSS developers. Here's been discussed in Japanese. Thanks.

作業ログ作成時の説明

以下のテンプレートを埋めてタイトルに設定します。埋め方例はスクロールすると見えてきます。

OSS Gate Workshop: ${LOCATION}: ${YEAR}-${MONTH}-${DAY}: ${アカウント名}: ${OSS名}: Work log

タイトル例↓:

OSS Gate Workshop: Tokyo: 2017-01-16: kou: Rabbit: Work log

OSS Gateワークショップ関連情報

hyuraku commented 6 years ago

Python Client for Google Maps Servicesのgithubのサイトを確認 https://github.com/googlemaps/google-maps-services-python

hyuraku commented 6 years ago

githubのサイトより、ライセンスが’Apache License 2.0’であるのを確認 問題なし! https://github.com/googlemaps/google-maps-services-python/blob/master/LICENSE

knokmki612 commented 6 years ago

今日はよろしくお願いします!

uchan-nos commented 6 years ago

よろしくお願いします!

hyuraku commented 6 years ago

DescriptionよりAPIの種類を確認 https://github.com/googlemaps/google-maps-services-python#description

hyuraku commented 6 years ago

RequirementsよりAPIを使うのに必要な環境を確認 以下必要な環境を記載 ・Python 2.7 or later. ・A Google Maps API key. https://github.com/googlemaps/google-maps-services-python#requirements

hyuraku commented 6 years ago

pythonのversionを確認

python --version

Python 2.7.10

hyuraku commented 6 years ago

使用するAPIを選択してkeyを入手 今回は’Directions API’を使う https://github.com/googlemaps/google-maps-services-python#api-keys

hyuraku commented 6 years ago

installを実行したが、正常に機能しなかった。 私のPCの問題かもしれない。 $ pip install -U googlemaps -bash: pip: command not found

https://github.com/googlemaps/google-maps-services-python#installation

hyuraku commented 6 years ago

試しにpip3でインストールをする 結果は成功、あとでpip3について復習といけない。

pip3 install -U googlemaps Collecting googlemaps Downloading googlemaps-2.5.1.tar.gz Collecting requests<3.0,>=2.11.1 (from googlemaps) Downloading requests-2.18.4-py2.py3-none-any.whl (88kB) 100% |████████████████████████████████| 92kB 1.9MB/s Collecting urllib3<1.23,>=1.21.1 (from requests<3.0,>=2.11.1->googlemaps) Downloading urllib3-1.22-py2.py3-none-any.whl (132kB) 100% |████████████████████████████████| 133kB 3.1MB/s Collecting idna<2.7,>=2.5 (from requests<3.0,>=2.11.1->googlemaps) Downloading idna-2.6-py2.py3-none-any.whl (56kB) 100% |████████████████████████████████| 61kB 4.5MB/s Collecting chardet<3.1.0,>=3.0.2 (from requests<3.0,>=2.11.1->googlemaps) Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB) 100% |████████████████████████████████| 143kB 3.9MB/s Collecting certifi>=2017.4.17 (from requests<3.0,>=2.11.1->googlemaps) Downloading certifi-2017.11.5-py2.py3-none-any.whl (330kB) 100% |████████████████████████████████| 337kB 2.5MB/s Building wheels for collected packages: googlemaps Running setup.py bdist_wheel for googlemaps ... done Stored in directory: /Users/yu-saka/Library/Caches/pip/wheels/04/e8/d1/ae5577b5339873e6a5dd55141d56e507cf281b137ef09ba924 Successfully built googlemaps Installing collected packages: urllib3, idna, chardet, certifi, requests, googlemaps Successfully installed certifi-2017.11.5 chardet-3.0.4 googlemaps-2.5.1 idna-2.6 requests-2.18.4 urllib3-1.22

hyuraku commented 6 years ago

先程までローカル環境で作業していたが、 ここで仮想環境で作業を行う。

理由はimportしたはずのgoogle mapsが importされていないとのメッセージが発生した。

sample.py

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='AIzaSyAvxxGQf3Xl6-cl_5VmZcNd_Mpebw2oUc0')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

python sample.py Traceback (most recent call last): File "sample.py", line 1, in import googlemaps ImportError: No module named googlemaps

hyuraku commented 6 years ago

仮想環境のpythonのversionを確認 3.5なので問題ない

python --version Python 3.5.2

hyuraku commented 6 years ago

下のリンク先のインストールをもとにgooglemapsをインストール 成功しました! https://github.com/googlemaps/google-maps-services-python#installation

pip install -U googlemaps Collecting googlemaps Downloading googlemaps-2.5.1.tar.gz Collecting requests<3.0,>=2.11.1 (from googlemaps) Downloading requests-2.18.4-py2.py3-none-any.whl (88kB) 100% |████████████████████████████████| 92kB 2.3MB/s Collecting idna<2.7,>=2.5 (from requests<3.0,>=2.11.1->googlemaps) Downloading idna-2.6-py2.py3-none-any.whl (56kB) 100% |████████████████████████████████| 61kB 3.6MB/s Collecting urllib3<1.23,>=1.21.1 (from requests<3.0,>=2.11.1->googlemaps) Downloading urllib3-1.22-py2.py3-none-any.whl (132kB) 100% |████████████████████████████████| 133kB 3.3MB/s Collecting chardet<3.1.0,>=3.0.2 (from requests<3.0,>=2.11.1->googlemaps) Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB) 100% |████████████████████████████████| 143kB 4.7MB/s Collecting certifi>=2017.4.17 (from requests<3.0,>=2.11.1->googlemaps) Downloading certifi-2017.11.5-py2.py3-none-any.whl (330kB) 100% |████████████████████████████████| 337kB 2.5MB/s Building wheels for collected packages: googlemaps Running setup.py bdist_wheel for googlemaps ... done Stored in directory: /root/.cache/pip/wheels/04/e8/d1/ae5577b5339873e6a5dd55141d56e507cf281b137ef09ba924 Successfully built googlemaps Installing collected packages: idna, urllib3, chardet, certifi, requests, googlemaps Successfully installed certifi-2017.11.5 chardet-3.0.4 googlemaps-2.5.1 idna-2.6 requests-2.18.4 urllib3-1.22 You are using pip version 8.1.2, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.

hyuraku commented 6 years ago

実際にUsageをもとに動かしてみたが エラーが発生してしまった。 https://github.com/googlemaps/google-maps-services-python#usage

sample.py

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='MY_API_KEY')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=n

python sample.py

Traceback (most recent call last): File "sample.py", line 7, in geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA') File "/root/.pyenv/versions/3.5.2/lib/python3.5/site-packages/googlemaps/client.py", line 356, in wrapper result = func(*args, **kwargs) File "/root/.pyenv/versions/3.5.2/lib/python3.5/site-packages/googlemaps/geocoding.py", line 68, in geocode return client._request("/maps/api/geocode/json", params)["results"] File "/root/.pyenv/versions/3.5.2/lib/python3.5/site-packages/googlemaps/client.py", line 253, in _request result = self._get_body(response) File "/root/.pyenv/versions/3.5.2/lib/python3.5/site-packages/googlemaps/client.py", line 280, in _get_body body["error_message"]) googlemaps.exceptions.ApiError: REQUEST_DENIED (This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/geocoding_backend?project=_)

hyuraku commented 6 years ago

再度APIを発行して入れ直す エラーメッセージは表示されず、成功しました!

失敗した理由は、制限時間を過ぎたAPIを使用していたためかもしれない。

python sample.py

hyuraku commented 6 years ago

Usageにはもう一つClientIDとClientSecretを使用するやり方がある。 このIDとSecretは、Google Maps APIs Premium Plan ライセンスを購入しないと入手できないので 今回はPassする

https://github.com/googlemaps/google-maps-services-python#usage https://developers.google.com/maps/documentation/directions/get-api-key#client-id

gmaps = googlemaps.Client(client_id=client_id, client_secret=client_secret)

# Geocoding and address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)
hyuraku commented 6 years ago

テスト環境の作り方のページを確認。 これが一番最後の項目なのですか・・・・・・

https://github.com/googlemaps/google-maps-services-python#building-the-project

hyuraku commented 6 years ago

ためしにUsageのSampleコードに一行追加して 出力を確認する。

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='MY_API_KEY')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

print(directions_result)#追加したコード

python sample.py [{'warnings': ['Walking directions are in beta. Use caution – This route may be missing sidewalks or pedestrian paths.'], 'summary': '', 'overviewpolyline': {'points': 'lzvmE}r{y[m@A@Yr@JBChAh@ANbAHpAJjDh@z@Cp@MrAs@fAeAZi@Zm@z@cAnBmABk@t@SnCUBRR?tARr@JFt@bDp@~CAb@PbCtAd@\Sd@rBzAbAAzAbBhEfGf@n@r@zAfABfA|AAjAlBhBdFxD~@v@vDdDdAhArBnCdCjEfBtDCxGbAnDRAf@Db@vCd@xB|AtGtAfGl@hCrApE~@hD\vAj@DjAtF~@fHPnCBrBDfKO~ECbDMzCUnBm@jCsA~DwArCiArB]t@e@pA}@bDmBpHw@rCo@vCa@zDEB?zDLdC\tF@zEVfCD|CODW~BcBnI[|BYDCpBD~BRrCj@pGVFE~CU|Da@nEc@xDe@zBoAnFq@`DYrAcCfKgBzH}AdGgAhD}@bDUdAq@rE[|CK~DOtGC|ABjAEvA?rBWfEa@bDO|@@nAe@fBm@xBeBHmArEi@jC{BbJyAvGuCxLaBlFa@bAcCtFgBxD{BbFs@pAqBdDiDfGeBlC_FvGcDrEy@xAaAtBu@tBy@xCgBhJc@bCi@lEq@|Gu@nHUzAq@nCaAdCc@Ay@xAW@_@h@}@A}AdB}EhEcBzBgAjBoBdEaAnAaBdBcBxByBzDeE|HgFtJsAdDsArDe@rAcAvDsAlGeBrIcBnIc@zCYbEEvELbEd@bF^hGPhEBzDWfHMjCKhAOvA{@jESbAa@nDm@~FSbDSlICtCFnHHzFXjDp@jE^zCNxBFjB?zEGlIMvMIvHBlBI|ESDc@fDq@|CuBdGsACgA|AeAnA}A|A}AjAuA~@yAz@s@^{Az@_Bv@_GrDqPhKqEpCyAjAeAp@{@r@sAx@wBrA{HvFsAnAcBlB{@z@oBBwApAoHzH_QhRyD|DuAxAcD~D_HrHk@bAiAzAs@dAqFnJm@hAeBxCyEhJmAfC{CjFsFdK{BtE}CdEwAfCsD~G{@dBJe@|A_DfAkBtCqFpAaCVi@Wh@qACcCtEcAdBU@cB~AeCBaEfB}CbA{Bn@}Bb@]BUBaAHaDHqBEA@sCKyCe@eCc@sASm@C{CI_A@eCVkCt@mBlAmBrAsBlBiBCU@@VXToAfCq@BGb@EZI@a@BG?KEEGSNi@Vy@NW?w@JIHONYLc@DQACVUzAo@tE'}, 'bounds': {'southwest': {'lat': -33.8978278, 'lng': 151.0012743}, 'northeast': {'lat': -33.8146729, 'lng': 151.208821}}, 'legs': [{'via_waypoint': [], 'steps': [{'steps': [{'distance': {'value': 25, 'text': '25 m'}, 'travel_mode': 'WALKING', 'polyline': {'points': 'lzvmE}r{y[OA]?'}, 'duration': {'value': 18, 'text': '1 min'}, 'start_location': {'lat': -33.8731872, 'lng': 151.2070292}, 'end_location': {'lat': -33.8729583, 'lng': 151.207043}, 'html_instructions': 'Head <b>north</b> on <b>George St</b> toward <b>Park St</b>'}, {'distance': {'value': 12, 'text': '12 m'}, 'travel_mode': 'WALKING', 'polyline': {'points': '~xvmE_s{y[@Y'}, 'duration': {'value': 13, 'text': '1 min'}, 'start_location': {'lat': -33.8729583, 'lng': 151.207043}, 'end_location': {'lat': -33.8729727, 'lng': 151.2071669}, 'maneuver': 'turn-right', 'html_instructions': 'Turn <b>right</b> onto <b>Park St</b>'}, {'distance': {'value': 30, 'text': '30 m'}, 'travel_mode': 'WALKING', 'polyline': {'points': 'yvmEys{y[r@JBC'}, 'duration': {'value': 27, 'text': '1 min'}, 'start_location': {'lat': -33.8729727, 'lng': 151.2071669}, 'end_location': {'lat': -33.87325, 'lng': 151.20713}, 'maneuver': 'turn-right', 'html_instructions': 'Turn right'}, {'distance': {'value': 45, 'text': '45 m'}, 'travel_mode': 'WALKING', 'polyline': {'points': 'xzvmEqs{y[hAh@'}, 'duration': {'value': 45, 'text': '1 min'}, 'end_location': {'lat': -33.87362299999999, 'lng': 151.206924}, 'start_location': {'lat': -33.87325, 'lng': 151.20713}}], 'distance': {'value': 112, 'text': '0.1 km'}, 'travel_mode': 'WALKING', 'polyline': {'points': 'lzvmE}r{y[OA]?@Yr@JBChAh@'}, 'duration': {'value': 103, 'text': '2 mins'}, 'start_location': {'lat': -33.8731872, 'lng': 151.2070292}, 'end_location': {'lat': -33.87362299999999, 'lng': 151.206924}, 'html_instructions': 'Walk to Town Hall Station'}, {'distance': {'value': 25312, 'text': '25.3 km'}, 'travelmode': 'TRANSIT', 'polyline': {'points': 'b}vmEgr{y[ANbAHnAJ@?@?hDh@D?T?R?JCFAh@Kj@Uf@]b@@b@e@LQLWLWLULUl@m@t@i@x@c@z@]d@MVI\I~AQn@CF@hAN@?L@H?H?^Dt@LZDHBB?H@LBZF~BZv@L@@~AXd@JZHd@LLBd@NdA^PFPHb@T~A~@d@\Sd@@VpAbALHt@v@~@bAZ^PR^j@zAvBz@nAf@n@r@zAl@x@Xf@Xb@l@x@b@j@\\^Z\\ZZTR^Z|BbBv@j@f@@FFFDb@@FDJHXVNLhB~Ab@^LL^@LJHLLNNR~@lAT\DDh@z@@r@r@tAj@fAHRP@^v@l@BVr@\\~@\\bATv@Tv@HVLf@Hb@H\\PfATxAPpAPdARbAPt@FXZpAT~@b@hBPx@BFDTJ@DTBFNn@R~@FXFTNl@Lj@Tv@V|@Rp@Ph@j@nBRx@Nh@Ll@RfAP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@A@_@CqBIgAMqAWUEoB]sASm@CgBGs@AA@eCVw@PsAb@e@ZGDe@ZYNEBu@h@UP[R{@x@KHKJ@\]^kA`BOVEH@V'}, 'duration': {'value': 2088, 'text': '35 mins'}, 'start_location': {'lat': -33.87362299999999, 'lng': 151.206924}, 'end_location': {'lat': -33.8175076, 'lng': 151.0050435}, 'transit_details': {'departure_stop': {'location': {'lat': -33.87362299999999, 'lng': 151.206924}, 'name': 'Town Hall Station'}, 'line': {'vehicle': {'icon': '//maps.gstatic.com/mapfiles/transit/iw2/6/rail2.png', 'type': 'HEAVY_RAIL', 'name': 'Train', 'local_icon': '//maps.gstatic.com/mapfiles/transit/iw2/6/au-sydney-rail.png'}, 'agencies': [{'phone': '011 61 13 15 00', 'url': 'http://www.sydneytrains.info/', 'name': 'Sydney Trains'}], 'short_name': 'T1', 'color': '#f9a825', 'text_color': '#ffffff', 'name': 'North Shore, Northern & Western Line'}, 'num_stops': 8, 'arrival_stop': {'location': {'lat': -33.8175076, 'lng': 151.0050435}, 'name': 'Parramatta'}, 'headsign': 'Richmond via Central', 'arrival_time': {'value': 1511582808, 'text': '3:06pm', 'time_zone': 'Australia/Sydney'}, 'departure_time': {'value': 1511580720, 'text': '2:32pm', 'time_zone': 'Australia/Sydney'}}, 'html_instructions': 'Train towards Richmond via Central'}, {'steps': [{'distance': {'value': 160, 'text': '0.2 km'}, 'travel_mode': 'WALKING', 'polyline': {'points': 'l~kmEodtx[XTq@rA]r@Q\IRQf@CFEVAJEZ'}, 'duration': {'value': 110, 'text': '2 mins'}, 'start_location': {'lat': -33.8175076, 'lng': 151.0050435}, 'end_location': {'lat': -33.8169201, 'lng': 151.0034428}, 'html_instructions': 'Head northwest on Liverpool-Parramatta Transitway toward Church St'}, {'distance': {'value': 42, 'text': '42 m'}, 'travel_mode': 'WALKING', 'polyline': {'points': 'vzkmEozsx[I@E@[@E?A?A?CAAACAEG'}, 'duration': {'value': 26, 'text': '1 min'}, 'start_location': {'lat': -33.8169201, 'lng': 151.0034428}, 'end_location': {'lat': -33.8165694, 'lng': 151.0034844}, 'maneuver': 'turn-right', 'html_instructions': 'Turn right onto Church St'}, {'distance': {'value': 183, 'text': '0.2 km'}, 'travel_mode': 'WALKING', 'polyline': {'points': 'pxkmEwzsx[SN[NMFMDIBK@UBG@IAC?A?G?YDQBC@CBA@A@A@CBKJKFMDOBG@E?E?QA'}, 'duration': {'value': 134, 'text': '2 mins'}, 'start_location': {'lat': -33.8165694, 'lng': 151.0034844}, 'end_location': {'lat': -33.8150393, 'lng': 151.0029224}, 'maneuver': 'turn-left', 'html_instructions': 'Turn left to stay on Church St'}, {'distance': {'value': 158, 'text': '0.2 km'}, 'travel_mode': 'WALKING', 'polyline': {'points': '~nkmEgwsx[CVIf@Kr@[xBSzA'}, 'duration': {'value': 144, 'text': '2 mins'}, 'start_location': {'lat': -33.8150393, 'lng': 151.0029224}, 'end_location': {'lat': -33.8146729, 'lng': 151.0012743}, 'maneuver': 'turn-left', 'html_instructions': 'Turn left onto Macquarie St'}], 'distance': {'value': 543, 'text': '0.5 km'}, 'travel_mode': 'WALKING', 'polyline': {'points': 'l~kmEodtx[XTq@rA]r@Q\IRQf@CFEVAJEZI@E@[@E?A?A?CAAACAEGSN[NMFMDIBK@UBG@IAC?A?G?YDQBC@CBA@A@A@CBKJKFMDOBG@E?E?QACVIf@Kr@[xBSzA'}, 'duration': {'value': 414, 'text': '7 mins'}, 'start_location': {'lat': -33.8175076, 'lng': 151.0050435}, 'end_location': {'lat': -33.8146729, 'lng': 151.0012743}, 'html_instructions': 'Walk to Parramatta NSW 2150, Australia'}], 'end_address': 'Parramatta NSW 2150, Australia', 'end_location': {'lat': -33.8146729, 'lng': 151.0012743}, 'arrival_time': {'value': 1511583263, 'text': '3:14pm', 'time_zone': 'Australia/Sydney'}, 'distance': {'value': 25967, 'text': '26.0 km'}, 'duration': {'value': 2650, 'text': '44 mins'}, 'start_address': '483 George St, Sydney NSW 2000, Australia', 'traffic_speed_entry': [], 'departure_time': {'value': 1511580613, 'text': '2:30pm', 'time_zone': 'Australia/Sydney'}, 'start_location': {'lat': -33.8731872, 'lng': 151.2070292}}], 'waypoint_order': [], 'copyrights': 'Map data ©2017 Google'}]

hyuraku commented 6 years ago

午前のFB

・pipでインストールでできなかった場合のやりかたがあると良い。 ・sample.pyのdirections_resultの中身の確認方法を知りたい。単にprintするだけでは読めないのでどのようなコマンドを実行するのが良いか知りたい。 ・テスト環境の構築の項目は冒頭から見たかった。

hyuraku commented 6 years ago

今度はreverse_geocode_resultを出力させる。

sample.py

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='AIzaSyAfXJ_KBd50hT11YO8KMP5DeFx3fpwdw4E')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

print(reverse_geocode_result)#追加したコード

python sample.py [{'geometry': {'viewport': {'southwest': {'lat': 40.7128715197085, 'lng': -73.9626392802915}, 'northeast': {'lat': 40.71556948029149, 'lng': -73.95994131970849}}, 'location_type': 'ROOFTOP', 'location': {'lat': 40.7142205, 'lng': -73.9612903}}, 'place_id': 'ChIJd8BlQ2BZwokRAFUEcm_qrcA', 'formatted_address': '277 Bedford Ave, Brooklyn, NY 11211, USA', 'address_components': [{'long_name': '277', 'short_name': '277', 'types': ['street_number']}, {'long_name': 'Bedford Avenue', 'short_name': 'Bedford Ave', 'types': ['route']}, {'long_name': 'Williamsburg', 'short_name': 'Williamsburg', 'types': ['neighborhood', 'political']}, {'long_name': 'Brooklyn', 'short_name': 'Brooklyn', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'Kings County', 'short_name': 'Kings County', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'New York', 'short_name': 'NY', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}, {'long_name': '11211', 'short_name': '11211', 'types': ['postal_code']}], 'types': ['street_address']}, {'geometry': {'viewport': {'southwest': {'lat': 40.7129720197085, 'lng': -73.96249998029151}, 'northeast': {'lat': 40.71566998029149, 'lng': -73.95980201970849}}, 'location_type': 'GEOMETRIC_CENTER', 'location': {'lat': 40.714321, 'lng': -73.961151}}, 'place_id': 'ChIJi27VXGBZwokRM8ErPyB91yk', 'formatted_address': 'Grand St/Bedford Av, Brooklyn, NY 11211, USA', 'address_components': [{'long_name': 'Grand St/Bedford Av', 'short_name': 'Grand St/Bedford Av', 'types': ['bus_station', 'establishment', 'point_of_interest', 'transit_station']}, {'long_name': 'Williamsburg', 'short_name': 'Williamsburg', 'types': ['neighborhood', 'political']}, {'long_name': 'Brooklyn', 'short_name': 'Brooklyn', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'Kings County', 'short_name': 'Kings County', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'New York', 'short_name': 'NY', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}, {'long_name': '11211', 'short_name': '11211', 'types': ['postal_code']}], 'types': ['bus_station', 'establishment', 'point_of_interest', 'transit_station']}, {'geometry': {'viewport': {'southwest': {'lat': 40.6979329, 'lng': -73.96984499999999}, 'northeast': {'lat': 40.7251773, 'lng': -73.936498}}, 'bounds': {'southwest': {'lat': 40.6979329, 'lng': -73.96984499999999}, 'northeast': {'lat': 40.7251773, 'lng': -73.936498}}, 'location_type': 'APPROXIMATE', 'location': {'lat': 40.7081156, 'lng': -73.9570696}}, 'place_id': 'ChIJQSrBBv1bwokRbNfFHCnyeYI', 'formatted_address': 'Williamsburg, Brooklyn, NY, USA', 'address_components': [{'long_name': 'Williamsburg', 'short_name': 'Williamsburg', 'types': ['neighborhood', 'political']}, {'long_name': 'Brooklyn', 'short_name': 'Brooklyn', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'New York', 'short_name': 'New York', 'types': ['locality', 'political']}, {'long_name': 'Kings County', 'short_name': 'Kings County', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'New York', 'short_name': 'NY', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'types': ['neighborhood', 'political']}, {'geometry': {'viewport': {'southwest': {'lat': 40.551042, 'lng': -74.05663}, 'northeast': {'lat': 40.739446, 'lng': -73.8333651}}, 'bounds': {'southwest': {'lat': 40.551042, 'lng': -74.05663}, 'northeast': {'lat': 40.739446, 'lng': -73.8333651}}, 'location_type': 'APPROXIMATE', 'location': {'lat': 40.6781784, 'lng': -73.9441579}}, 'place_id': 'ChIJCSF8lBZEwokRhngABHRcdoI', 'formatted_address': 'Brooklyn, NY, USA', 'address_components': [{'long_name': 'Brooklyn', 'short_name': 'Brooklyn', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'New York', 'short_name': 'New York', 'types': ['locality', 'political']}, {'long_name': 'Kings County', 'short_name': 'Kings County', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'New York', 'short_name': 'NY', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'geometry': {'viewport': {'southwest': {'lat': 40.4773991, 'lng': -74.25908989999999}, 'northeast': {'lat': 40.9175771, 'lng': -73.70027209999999}}, 'bounds': {'southwest': {'lat': 40.4773991, 'lng': -74.25908989999999}, 'northeast': {'lat': 40.9175771, 'lng': -73.70027209999999}}, 'location_type': 'APPROXIMATE', 'location': {'lat': 40.7127753, 'lng': -74.0059728}}, 'place_id': 'ChIJOwg_06VPwokRYv534QaPC8g', 'formatted_address': 'New York, NY, USA', 'address_components': [{'long_name': 'New York', 'short_name': 'New York', 'types': ['locality', 'political']}, {'long_name': 'New York', 'short_name': 'NY', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'types': ['locality', 'political']}, {'geometry': {'viewport': {'southwest': {'lat': 40.7008331, 'lng': -73.9644697}, 'northeast': {'lat': 40.7280089, 'lng': -73.9207299}}, 'bounds': {'southwest': {'lat': 40.7008331, 'lng': -73.9644697}, 'northeast': {'lat': 40.7280089, 'lng': -73.9207299}}, 'location_type': 'APPROXIMATE', 'location': {'lat': 40.7093358, 'lng': -73.9565551}}, 'place_id': 'ChIJvbEjlVdZwokR4KapM3WCFRw', 'formatted_address': 'Brooklyn, NY 11211, USA', 'address_components': [{'long_name': '11211', 'short_name': '11211', 'types': ['postal_code']}, {'long_name': 'Brooklyn', 'short_name': 'Brooklyn', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'New York', 'short_name': 'New York', 'types': ['locality', 'political']}, {'long_name': 'New York', 'short_name': 'NY', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'types': ['postal_code']}, {'geometry': {'viewport': {'southwest': {'lat': 40.551042, 'lng': -74.05663}, 'northeast': {'lat': 40.739446, 'lng': -73.8333651}}, 'bounds': {'southwest': {'lat': 40.551042, 'lng': -74.05663}, 'northeast': {'lat': 40.739446, 'lng': -73.8333651}}, 'location_type': 'APPROXIMATE', 'location': {'lat': 40.6528762, 'lng': -73.95949399999999}}, 'place_id': 'ChIJOwE7_GTtwokRs75rhW4_I6M', 'formatted_address': 'Kings County, Brooklyn, NY, USA', 'address_components': [{'long_name': 'Kings County', 'short_name': 'Kings County', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'Brooklyn', 'short_name': 'Brooklyn', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'New York', 'short_name': 'NY', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'types': ['administrative_area_level_2', 'political']}, {'geometry': {'viewport': {'southwest': {'lat': 39.49853299999999, 'lng': -75.3585939}, 'northeast': {'lat': 41.6018065, 'lng': -71.856214}}, 'bounds': {'southwest': {'lat': 39.49853299999999, 'lng': -75.3585939}, 'northeast': {'lat': 41.6018065, 'lng': -71.856214}}, 'location_type': 'APPROXIMATE', 'location': {'lat': 40.9590293, 'lng': -74.0300122}}, 'place_id': 'ChIJ3YJV4PRWwokRFFI21ZrHXtQ', 'formatted_address': 'New York-Northern New Jersey-Long Island, NY-NJ-PA, USA', 'address_components': [{'long_name': 'New York-Northern New Jersey-Long Island, NY-NJ-PA', 'short_name': 'New York-Northern New Jersey-Long Island, NY-NJ-PA', 'types': ['political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'types': ['political']}, {'geometry': {'viewport': {'southwest': {'lat': 39.475198, 'lng': -75.3587649}, 'northeast': {'lat': 42.0809059, 'lng': -71.777491}}, 'bounds': {'southwest': {'lat': 39.475198, 'lng': -75.3587649}, 'northeast': {'lat': 42.0809059, 'lng': -71.777491}}, 'location_type': 'APPROXIMATE', 'location': {'lat': 40.7127761, 'lng': -74.0059544}}, 'place_id': 'ChIJ-5Z24NaGwokRiMh4Rj8FNMo', 'formatted_address': 'New York Metropolitan Area, USA', 'address_components': [{'long_name': 'New York Metropolitan Area', 'short_name': 'New York Metropolitan Area', 'types': ['political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'types': ['political']}, {'geometry': {'viewport': {'southwest': {'lat': 40.4773991, 'lng': -79.7625901}, 'northeast': {'lat': 45.015865, 'lng': -71.777491}}, 'bounds': {'southwest': {'lat': 40.4773991, 'lng': -79.7625901}, 'northeast': {'lat': 45.015865, 'lng': -71.777491}}, 'location_type': 'APPROXIMATE', 'location': {'lat': 43.2994285, 'lng': -74.21793260000001}}, 'place_id': 'ChIJqaUj8fBLzEwRZ5UY3sHGz90', 'formatted_address': 'New York, USA', 'address_components': [{'long_name': 'New York', 'short_name': 'NY', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'types': ['administrative_area_level_1', 'political']}]

onk commented 6 years ago

作業ログを見て、3カ所ほどフィードバックポイントがあるのかなと感じました。

pip で入らないけど pip3 で入った

pip の周りは python2 / python3 でよく引っかかるところなので フィードバックポイントではあるんですが 「ライブラリの使い方」というよりは「Python の使い方」に近いので このライブラリにフィードバックするのは少し悩ましい感じですね。

API key が This API project is not authorized to use this API. と言われる

これもライブラリの問題ではないので、あればより親切かもしれないけど ライブラリの責務というには少し難しいと思います。

directions_result を表示すると謎の文字列が表示される

これはとても良いフィードバックポイントだと思いました。

とはいえこの API を叩くと

"overview_polyline" : {
   "points" : "_rtwFpgubMt ...overview polyline truncated in this example"
},

が返ってくるのは https://developers.google.com/maps/documentation/directions/ にも書いてあるので API の利用者はライブラリを使う前に知っている知識なのかもしれません。

とか

とかになるんでしょうか。

print デバッグはよくやると思うので、

# returns Dictionary

とコメントがあると助かるとか、 ターミナルにいっぱい文字が出てしんどいので

print(directions_result["bounds"])

と確認方法を書いておいて欲しいとかは、あると嬉しいドキュメントだと思いました。

hyuraku commented 6 years ago

@onk ありがとうございます! これからIssueを送るので参考にさせていただきます!

hyuraku commented 6 years ago

環境 macOS Sierra 10.12.6 python:3.5.2 googlemaps:2.5.1

気持ち:サンプルコードのdirections_resultを出力させたい。

print(directions_result)を実行したが、返ってくるデータの可読性が低く、出力を確認できなかった。 可読性が高く、戻り値を確認できるコマンドを記載してほしい。

hyuraku commented 6 years ago

下のファイルを実行

sample.py

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='MY_API_KEY')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

print(directions_result) #add new code.

python sample.py [{'bounds': {'northeast': {'lat': -33.8146729, 'lng': 151.208821}, 'southwest': {'lat': -33.8978278, 'lng': 151.0012743}}, 'copyrights': 'Map data ©2017 Google', 'legs': [{'arrival_time': {'text': '5:14pm', 'time_zone': 'Australia/Sydney', 'value': 1511590463}, 'departure_time': {'text': '4:30pm', 'time_zone': 'Australia/Sydney', 'value': 1511587813}, 'distance': {'text': '26.0 km', 'value': 25967}, 'duration': {'text': '44 mins', 'value': 2650}, 'end_address': 'Parramatta NSW 2150, Australia', 'end_location': {'lat': -33.8146729, 'lng': 151.0012743}, 'start_address': '483 George St, Sydney NSW 2000, Australia', 'start_location': {'lat': -33.8731872, 'lng': 151.2070292}, 'steps': [{'distance': {'text': '0.1 km', 'value': 112}, 'duration': {'text': '2 mins', 'value': 103}, 'end_location': {'lat': -33.87362299999999, 'lng': 151.206924}, 'html_instructions': 'Walk to Town Hall Station', 'polyline': {'points': 'lzvmE}r{y[OA]?@Yr@JBChAh@'}, 'start_location': {'lat': -33.8731872, 'lng': 151.2070292}, 'steps': [{'distance': {'text': '25 m', 'value': 25}, 'duration': {'text': '1 min', 'value': 18}, 'end_location': {'lat': -33.8729583, 'lng': 151.207043}, 'html_instructions': 'Head north on George St toward Park St', 'polyline': {'points': 'lzvmE}r{y[OA]?'}, 'start_location': {'lat': -33.8731872, 'lng': 151.2070292}, 'travel_mode': 'WALKING'}, {'distance': {'text': '12 m', 'value': 12}, 'duration': {'text': '1 min', 'value': 13}, 'end_location': {'lat': -33.8729727, 'lng': 151.2071669}, 'html_instructions': 'Turn right onto Park St', 'maneuver': 'turn-right', 'polyline': {'points': '~xvmE_s{y[@Y'}, 'start_location': {'lat': -33.8729583, 'lng': 151.207043}, 'travel_mode': 'WALKING'}, {'distance': {'text': '30 m', 'value': 30}, 'duration': {'text': '1 min', 'value': 27}, 'end_location': {'lat': -33.87325, 'lng': 151.20713}, 'html_instructions': 'Turn right', 'maneuver': 'turn-right', 'polyline': {'points': 'yvmEys{y[r@JBC'}, 'start_location': {'lat': -33.8729727, 'lng': 151.2071669}, 'travel_mode': 'WALKING'}, {'distance': {'text': '45 m', 'value': 45}, 'duration': {'text': '1 min', 'value': 45}, 'end_location': {'lat': -33.87362299999999, 'lng': 151.206924}, 'polyline': {'points': 'xzvmEqs{y[hAh@'}, 'start_location': {'lat': -33.87325, 'lng': 151.20713}, 'travel_mode': 'WALKING'}], 'travel_mode': 'WALKING'}, {'distance': {'text': '25.3 km', 'value': 25312}, 'duration': {'text': '35 mins', 'value': 2088}, 'end_location': {'lat': -33.8175076, 'lng': 151.0050435}, 'html_instructions': 'Train towards Richmond via Central', 'polyline': {'points': 'b}vmEgr{y[ANbAHnAJ@?@?hDh@D?T?R?JCFAh@Kj@Uf@]b@_@b@e@LQLWLWLULUl@m@t@i@x@c@z@]d@MVI\\I~AQn@CF@hAN@?L@H?H?^Dt@LZDHBB?H@LBZF~BZv@L@@~AXd@JZHd@LLBd@NdA^PFPHb@T~A~@d@\\Sd@@VpAbALHt@v@~@bAZ^PR^j@zAvBz@nAf@n@r@zAl@x@Xf@Xb@l@x@b@j@\^Z\ZZTR^Z|BbBv@j@f@@FFFDb@@FDJHXVNLhB~Ab@^LL^@LJHLLNNR~@lAT\\DDh@z@@r@r@tAj@fAHRP@^v@l@BVr@\~@\bATv@Tv@HVLf@Hb@H\PfATxAPpAPdARbAPt@FXZpAT~@b@hBPx@BFDTJ@DTBFNn@R~@FXFTNl@Lj@Tv@V|@Rp@Ph@j@nBRx@Nh@Ll@RfAPA@JBJDXRv@P|@^dBDR@rCFf@NvAL|ABp@@x@@x@@pA@|A?z@@zCAr@AZCh@GdB?F?VC|A?d@A@Ab@Er@C@Gh@E^CNCTI\\YlAERCJUr@Up@IX]~@Sb@O\\U@]n@k@bA]n@KTQ^MZWt@[fAa@zAAFCH{@hDk@tBM@i@pB[lAShAUlBKlAARClAAtA@dBBn@HtALbCLbB?F@DDf@JhADd@HbAHj@LzABfA@tAG|AGbAMpAIl@]lBc@xBQp@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Ip@OvA{@jEK^Gb@QvAOvAg@tEEh@IlAItAEjAEtACzACnAAhBAj@@bBDjE@lCFlBJBLhAPnADV@FVzAHt@DVNfA?DFd@Bh@@T@RBXBpA@zBA~AAdBA~@?DCDClAAhDA\\EEEpECdB?b@BhACdBEvBMdCEZIAIh@ETId@AHMl@UbAK@Sp@EJm@bBGRABQf@IRGNEJMTGLEF?@QXQVMTKPW\MPUZSV[@IHKJc@f@[XKJQNONUPOJg@\\g@\\]TA?MJo@^i@Z]TUHYNaAj@gAd@WPe@X[RkBjAqAx@uBpAgAp@_@T{@j@y@d@qAx@cAn@gAr@o@^g@X}@l@{@h@SLeA|@OJu@d@{@r@sAx@}A~@YRoBrAq@f@uB~Ac@ZYT[XCBYZ{@bAKJMNMLe@f@URc@@kA~@ONYTIFc@b@SRm@l@SRy@z@i@j@_@@_AbAUVc@d@q@t@YZOP]\\WZcAhA_AbAi@l@m@n@OR[\\g@h@YXQRm@n@o@p@m@n@e@d@u@t@k@j@i@l@aAhAaBtB{A~AyBC?@iAnAk@bAiAzAKLg@v@cBtCmAtBm@bAQ^e@~@GHYj@kAlBiBtDoBrDMVAnBu@jAeB~CyCnFyAtCMRmB`EmA~AoAdBMPiAtBcBbDoAzB{@dBJe@NYlAeCR@@Ad@w@JQ@ANYbBeD^o@nA}B@CVi@Wh@ABoA|B@n@cBdDOXA@KPe@v@A@S^w@v@k@f@}@l@gAr@w@^iCfAIDa@L@JqAb@{Bn@sATi@LE?E?KBE?QBC?aAHaDHoBEA?A??@A@_@CqBIgAMqAWUEoB]sASm@CgBGs@AA@eCVw@PsAb@e@ZGDe@ZYNEBu@h@UP[R{@x@KHKJ@\]^kABOVEH@V'}, 'start_location': {'lat': -33.87362299999999, 'lng': 151.206924}, 'transit_details': {'arrival_stop': {'location': {'lat': -33.8175076, 'lng': 151.0050435}, 'name': 'Parramatta'}, 'arrival_time': {'text': '5:06pm', 'time_zone': 'Australia/Sydney', 'value': 1511590008}, 'departure_stop': {'location': {'lat': -33.87362299999999, 'lng': 151.206924}, 'name': 'Town Hall Station'}, 'departure_time': {'text': '4:32pm', 'time_zone': 'Australia/Sydney', 'value': 1511587920}, 'headsign': 'Richmond via Central', 'line': {'agencies': [{'name': 'Sydney Trains', 'phone': '011 61 13 15 00', 'url': 'http://www.sydneytrains.info/'}], 'color': '#f9a825', 'name': 'North Shore, Northern & Western Line', 'short_name': 'T1', 'text_color': '#ffffff', 'vehicle': {'icon': '//maps.gstatic.com/mapfiles/transit/iw2/6/rail2.png', 'local_icon': '//maps.gstatic.com/mapfiles/transit/iw2/6/au-sydney-rail.png', 'name': 'Train', 'type': 'HEAVY_RAIL'}}, 'num_stops': 8}, 'travel_mode': 'TRANSIT'}, {'distance': {'text': '0.5 km', 'value': 543}, 'duration': {'text': '7 mins', 'value': 414}, 'end_location': {'lat': -33.8146729, 'lng': 151.0012743}, 'html_instructions': 'Walk to Parramatta NSW 2150, Australia', 'polyline': {'points': 'l~kmEodtx[XTq@rA]r@Q\\IRQf@CFEVAJEZI@E@[@E?A?A?CAAACAEGSN[NMFMDIBK@UBG@IAC?A?G?YDQBC@CBA@A@A@CBKJKFMDOBG@E?E?QACVIf@Kr@[xBSzA'}, 'start_location': {'lat': -33.8175076, 'lng': 151.0050435}, 'steps': [{'distance': {'text': '0.2 km', 'value': 160}, 'duration': {'text': '2 mins', 'value': 110}, 'end_location': {'lat': -33.8169201, 'lng': 151.0034428}, 'html_instructions': 'Head <b>northwest</b> on <b>Liverpool-Parramatta Transitway</b> toward <b>Church St</b>', 'polyline': {'points': 'l~kmEodtx[XTq@rA]r@Q\\IRQf@CFEVAJEZ'}, 'start_location': {'lat': -33.8175076, 'lng': 151.0050435}, 'travel_mode': 'WALKING'}, {'distance': {'text': '42 m', 'value': 42}, 'duration': {'text': '1 min', 'value': 26}, 'end_location': {'lat': -33.8165694, 'lng': 151.0034844}, 'html_instructions': 'Turn <b>right</b> onto <b>Church St</b>', 'maneuver': 'turn-right', 'polyline': {'points': 'vzkmEozsx[I@E@[@E?A?A?CAAACAEG'}, 'start_location': {'lat': -33.8169201, 'lng': 151.0034428}, 'travel_mode': 'WALKING'}, {'distance': {'text': '0.2 km', 'value': 183}, 'duration': {'text': '2 mins', 'value': 134}, 'end_location': {'lat': -33.8150393, 'lng': 151.0029224}, 'html_instructions': 'Turn <b>left</b> to stay on <b>Church St</b>', 'maneuver': 'turn-left', 'polyline': {'points': 'pxkmEwzsx[SN[NMFMDIBK@UBG@IAC?A?G?YDQBC@CBA@A@A@CBKJKFMDOBG@E?E?QA'}, 'start_location': {'lat': -33.8165694, 'lng': 151.0034844}, 'travel_mode': 'WALKING'}, {'distance': {'text': '0.2 km', 'value': 158}, 'duration': {'text': '2 mins', 'value': 144}, 'end_location': {'lat': -33.8146729, 'lng': 151.0012743}, 'html_instructions': 'Turn <b>left</b> onto <b>Macquarie St</b>', 'maneuver': 'turn-left', 'polyline': {'points': '~nkmEgwsx[CVIf@Kr@[xBSzA'}, 'start_location': {'lat': -33.8150393, 'lng': 151.0029224}, 'travel_mode': 'WALKING'}], 'travel_mode': 'WALKING'}], 'traffic_speed_entry': [], 'via_waypoint': []}], 'overview_polyline': {'points': 'lzvmE}r{y[m@A@Yr@JBChAh@ANbAHpAJjDh@z@Cp@MrAs@fAeAZi@Zm@z@cAnBmABk@t@SnCUBRR?tARr@JFt@bDp@~CAb@PbCtAd@\\Sd@rBzAbAAzAbBhEfGf@n@r@zAfABfA|AAjAlBhBdFxD~@v@vDdDdAhArBnCdCjEfBtDCxGbAnDRAf@Db@vCd@xB|AtGtAfGl@hCrApE~@hD\\vAj@DjAtF~@fHPnCBrBDfKO~ECbDMzCUnBm@jCsA~DwArCiArB]t@e@pA}@bDmBpHw@rCo@vCa@zDEB?zDLdC\\tF@zEVfCD|CODW~BcBnI[|BYDCpBD~BRrCj@pGVFE~CU|Da@nEc@xDe@zBoAnFq@DYrAcCfKgBzH}AdGgAhD}@bDUdAq@rE[|CK~DOtGC|ABjAEvA?rBWfEa@bDO|@_@nAe@fBm@xBeBHmArEi@jC{BbJyAvGuCxLaBlFa@bAcCtFgBxD{BbFs@pAqBdDiDfGeBlC_FvGcDrEy@xAaAtBu@tBy@xCgBhJc@bCi@lEq@|Gu@nHUzAq@nCaAdCc@Ay@xAW@_@h@}@A}AdB}EhEcBzBgAjBoBdEaAnAaBdBcBxByBzDeE|HgFtJsAdDsArDe@rAcAvDsAlGeBrIcBnIc@zCYbEEvELbEd@bF^hGPhEBzDWfHMjCKhAOvA{@jESbAa@nDm@~FSbDSlICtCFnHHzFXjDp@jE^zCNxBFjB?zEGlIMvMIvHBlBI|ESDc@fDq@|CuBdGsACgA|AeAnA}A|A}AjAuA~@yAz@s@^{Az@_Bv@_GrDqPhKqEpCyAjAeAp@{@r@sAx@wBrA{HvFsAnAcBlB{@z@oBBwApAoHzH_QhRyD|DuAxAcD~D_HrHk@bAiAzAs@dAqFnJm@hAeBxCyEhJmAfC{CjFsFdK{BtE}CdEwAfCsD~G{@dBJe@|A_DfAkBtCqFpAaCVi@Wh@qACcCtEcAdBU@cB~AeCBaEfB}CbA{Bn@}Bb@]BUBaAHaDHqBEA@sCKyCe@eCc@sASm@C{CI_A@eCVkCt@mBlAmBrAsBlBiBCU@@VXToAfCq@`BGb@EZI@a@BG?KEEGSNi@Vy@NW?w@JIHONYLc@DQACVUzAo@tE'}, 'summary': '', 'warnings': ['Walking directions are in beta. Use caution – This route may be missing sidewalks or pedestrian paths.'], 'waypoint_order': []}]

hyuraku commented 6 years ago

環境 macOS Sierra 10.12.6 python:3.5.2 googlemaps:2.5.1

print(directions_result)を実行したが、返ってくるデータの可読性が低く、出力を確認できなかった。 可読性が高く、戻り値を確認できるコマンドがあれば記載してほしい。

hyuraku commented 6 years ago

sample1.py

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='MY_API_KEY')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

print(directions_result) #add new code.

実行結果 https://gist.github.com/hyuraku/ef1481f57d6cab8c44a9c2b2c3024d9f

hyuraku commented 6 years ago

環境 macOS Sierra 10.12.6 python:3.5.2 googlemaps:2.5.1

print(directions_result)を実行したが、返ってくるデータの可読性が低く、出力を確認できなかった。 下に実行したファイルを書きました。 sample1.py

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='MY_API_KEY')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

print(directions_result) #add new code.

出力は長くなったのでGithubGistにまとめ、下のリンクに載せました。 https://gist.github.com/hyuraku/ef1481f57d6cab8c44a9c2b2c3024d9f

可読性が高く、戻り値を確認できるコマンドがあれば記載してほしい。

hyuraku commented 6 years ago

タイトル:Usageのdirections_resultの返り値を確認できるコマンドを知りたい。

内容:

環境

macOS Sierra 10.12.6 python:3.5.2 googlemaps:2.5.1

問題点

print(directions_result)を実行したが、返ってくるデータの可読性が低く、出力を確認できなかった。 下のリンクをもとにsample1.pyを書きました。下にコードを記載。 https://github.com/googlemaps/google-maps-services-python#usage

sample1.py

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='MY_API_KEY')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

print(directions_result) #add new code.

こんな感じで読みにくいコードが出ました。

(略)
'polyline': {'points': 'b}vmEgr{y[ANbAHnAJ@?@?hDh@D?T?R?JCFAh@Kj@Uf@]b@_@b@e@LQLWLWLULUl@m@t@i@x@c@z@]d@MVI\I~AQn@CF@hAN@?L@H?H?^Dt@LZDHBB?
(略)

出力は長くなったのでGithubGistにまとめ、下のリンクに載せました。 https://gist.github.com/hyuraku/ef1481f57d6cab8c44a9c2b2c3024d9f

期待すること

可読性が高く、戻り値を確認できるコマンドがあれば記載してほしい。

hyuraku commented 6 years ago

一部抜粋

(略)---begin 'polyline': {'points': 'b}vmEgr{y[ANbAHnAJ@?@?hDh@D?T?R?JCFAh@Kj@Uf@]b@_@b@e@LQLWLWLULUl@m@t@i@x@c@z@]d@MVI\I~AQn@CF@hAN@?L@H?H?^Dt@LZDHBB? ---end(略)

knokmki612 commented 6 years ago

---begin--- (略) ほげほげ (略) ---end---

hyuraku commented 6 years ago

一部抜粋

(略)
'polyline': {'points': 'b}vmEgr{y[ANbAHnAJ@?@?hDh@D?T?R?JCFAh@Kj@Uf@]b@_@b@e@LQLWLWLULUl@m@t@i@x@c@z@]d@MVI\I~AQn@CF@hAN@?L@H?H?^Dt@LZDHBB?
(略)
hyuraku commented 6 years ago

Usageのdirections_resultの返り値を確認できるコマンドを知りたい。 How to know the command to check the return value of Usage's directions_result

Environment

macOS Sierra 10.12.6 python:3.5.2 googlemaps:2.5.1

Problem

I try to show the output of directions_result by print method, but the returning data was not readable and I could not check the output.

I wrote sample1.py based on the code of the link below.. I wrote the code below. https://github.com/googlemaps/google-maps-services-python#usage

sample1.py

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='MY_API_KEY')

# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))

# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

print(directions_result) #add new code.

Returned data is difficult for me like this:

(omit)
'polyline': {'points': 'b}vmEgr{y[ANbAHnAJ@?@?hDh@D?T?R?JCFAh@Kj@Uf@]b@_@b@e@LQLWLWLULUl@m@t@i@x@c@z@]d@MVI\I~AQn@CF@hAN@?L@H?H?^Dt@LZDHBB?
(omit)

Since the output is long, I put it in GithubGist and put it on the link below. https://gist.github.com/hyuraku/ef1481f57d6cab8c44a9c2b2c3024d9f

What I expect

Please tell me any commands for the check the readable return value of directions_result if you have.

knokmki612 commented 6 years ago

but the readability of the returning data was low

but the returned data wasn't readable

knokmki612 commented 6 years ago

I wrote the part of the code below. It is difficult for me to read.

Returned data is difficult for me like this:

knokmki612 commented 6 years ago

Please list any commands

Please tell me any commands

hyuraku commented 6 years ago

@knokmki612 英文のアドバイス、ありがとうございます!

hyuraku commented 6 years ago

googleにissueを送る。 これにてclose

knokmki612 commented 6 years ago

おつかれさまでした!立てたissueに返信が来てますね! issueでのやりとりに不安がありそうなら、 https://gitter.im/oss-gate/devel で相談してみてください!

直近の東京で開催される予定のOSS Gateのイベントは以下のとおりです!

是非よかったらまた参加してみてください!

hyuraku commented 6 years ago

@knokmki612 ありがとうございます! 今後のOssGateのイベントに参加してみたいです!