このセクションでは、プレイアブル ロケーションを取得する方法について説明するほか、API を呼び出す方法の例も紹介します。
プレイアブル ロケーションの取得
プレーヤーがゲームを進めていく中で、プレイアブル ロケーションのセットをオンデマンドで取得できます。大きなデータセットは、取得せずにキャッシュに保存して、長期間にわたって使用することもできます。
プレイアブル ロケーションのセットを取得するには、samplePlayableLocations
メソッドを呼び出します。呼び出しでは、検索する領域のほか、フィルタ条件も指定します。samplePlayableLocations
メソッドは、キュレートされたプレイアブル ロケーションと生成されたプレイアブル ロケーションの両方を含む PlayableLocation
オブジェクトのセットを返します。
HTTP リクエスト
次のコードは、HTTP POST リクエストを作成し、リクエスト本文にパラメータを渡して samplePlayableLocations
メソッドを呼び出す方法を示しています。
POST https://playablelocations.googleapis.com/v3:samplePlayableLocations?key=YOUR_API_KEY
リクエスト本文
samplePlayableLocations
メソッドを呼び出す際は、HTTP リクエストの本文で JSON オブジェクトを使用して呼び出しパラメータを渡します。
{
"areaFilter": {
"s2CellId": string,
},
"criteria": [
{
"gameObjectType": number,
"filter": {
"maxLocationCount": number,
"spacing": {
"minSpacingMeters": number,
"pointType": enum(PointType)
},
"includedTypes": [
string
],
},
"fieldsToReturn": string
}
]
}
リクエスト オブジェクト モデル
JSON サブオブジェクト間の関係を以下のイラストに示します。
例 1: リクエスト本文
filters
と fields_to_return
のコードサンプルを次に示します。
{
"area_filter":{
"s2_cell_id":7715420662885515264
},
"criteria":[
{
"gameObjectType":1,
"filter":{
"maxLocationCount":4,
"includedTypes":[
"food_and_drink"
]
},
"fields_to_return": {"paths": ["name"]}
},
{
"gameObjectType":2,
"filter":{
"maxLocationCount":4
},
"fields_to_return": {"paths": ["types", "snapped_point"]}}
]
}
例 2: リクエスト本文
さまざまなオブジェクト タイプの maxLocationCount
のコードサンプルを次に示します。
{
"area_filter":{
"s2_cell_id":7715420662885515264
},
"criteria":[
{
"gameObjectType":1,
"filter":{
"maxLocationCount":4,
"spacing":{
"minSpacingMeters":500
}
}
},
{
"gameObjectType":2,
"filter":{
"maxLocationCount":4,
"spacing":{
"minSpacingMeters":400
}
}
},
{
"gameObjectType":3,
"filter":{
"maxLocationCount":50,
"spacing":{
"minSpacingMeters":200
}
}
}
]
}