PowerApps で開発した、周辺のお店・病院等を検索してくれる「Nearby Places Seacher」の作成方法をご紹介します。
今回は、[検索] ボタンをクリックして、Google Maps API の情報をPowerAppsへ値を返す方法です。
こちらはMicrosoft Flowを利用します。
Microsoft Flow を追加
PowerApps の編集画面を開き、[アクション] → [Flows] → [新しいフローを追加] の順にクリックします。
すると、以下のような画面が表示されます。ここから画面下部の [新しいステップ] をクリックし、アクションが追加できます。
Microsoft Flow の作成
Flowの全体像
Flowの全体像は以下のようになっています。
Flow のアクション1つずつ説明していきます。
① PowerApps
こちらはFlow 作成時に自動で挿入されています。
編集する必要はございません。
② HTTP
こちらのアクションで Google Maps API を呼び出し、検索結果を取得します。
URIの中にある「HTTP_URI」というのは、PowerAppsでの引数を表します。
URIは以下の通りです。
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={['HTTP_URI']},{['HTTP_URI_1']}&rankby=distance&keyword={['HTTP_URI_2']}&key={['HTTP_URI_3']}
③ 要求
こちらのアクションで、「② HTTP」で取得した値をPowerAppsに返します。
「本文」には、「② HTTP」で取得した「本文」を選択します。
「JSONスキーマ」には、以下を入力します。
{ "type": "object", "properties": { "html_attributions": { "type": "array" }, "next_page_token": { "type": "string" }, "results": { "type": "array", "items": { "type": "object", "properties": { "geometry": { "type": "object", "properties": { "location": { "type": "object", "properties": { "lat": { "type": "number" }, "lng": { "type": "number" } } }, "viewport": { "type": "object", "properties": { "northeast": { "type": "object", "properties": { "lat": { "type": "number" }, "lng": { "type": "number" } } }, "southwest": { "type": "object", "properties": { "lat": { "type": "number" }, "lng": { "type": "number" } } } } } } }, "icon": { "type": "string" }, "id": { "type": "string" }, "name": { "type": "string" }, "opening_hours": { "type": "object", "properties": { "open_now": { "type": "boolean" } } }, "photos": { "type": "array", "items": { "type": "object", "properties": { "height": { "type": "integer" }, "html_attributions": { "type": "array", "items": { "type": "string" } }, "photo_reference": { "type": "string" }, "width": { "type": "integer" } }, "required": [ "height", "html_attributions", "photo_reference", "width" ] } }, "place_id": { "type": "string" }, "plus_code": { "type": "object", "properties": { "compound_code": { "type": "string" }, "global_code": { "type": "string" } } }, "rating": { "type": "number" }, "reference": { "type": "string" }, "scope": { "type": "string" }, "types": { "type": "array", "items": { "type": "string" } }, "user_ratings_total": { "type": "integer" }, "vicinity": { "type": "string" } }, "required": [ "geometry", "icon", "id", "name", "opening_hours", "place_id", "plus_code", "rating", "reference", "scope", "types", "user_ratings_total", "vicinity" ] } }, "status": { "type": "string" } } }
JSONスキーマの作り方は、後日また記事にしたいと思います。
これでMicrosoft Flowの完成です。
次回は、こちらの情報をPowerAppsで表示する方法をご紹介します。
余談
PowerAppsの画面を作ったり、SharePointのリストを作ったり、Flowを作ったり…
説明が下手であっちこっちにいって申し訳ありません。。。大目に見てください。。。