Places Aggregate API 用戶端程式庫

本頁面說明如何開始使用 Places Aggregate API 適用的用戶端程式庫。

如要進一步瞭解用戶端程式庫,請參閱「用戶端程式庫說明」。

安裝用戶端程式庫

Java

詳情請參閱「設定 Java 開發環境」。

如需安裝說明,請參閱 Java 版 Google Places Aggregate API 用戶端

Go

go get cloud.google.com/go/maps
詳情請參閱「設定 Go 開發環境」。

如需安裝說明,請參閱 Go 專用的 Google Places Aggregate API 用戶端

Node.js

npm install @googlemaps/areainsights
詳情請參閱「設定 Node.js 開發環境」一文。

如需完整安裝說明,請參閱「適用於 Node.js 的 Google Places Aggregate API 用戶端

Python

詳情請參閱「設定 Python 開發環境」。

如需完整的安裝操作說明,請參閱 適用於 Python 的 Google Places Aggregate API 用戶端

.Net

詳情請參閱「設定 .Net 開發環境」。

如需完整安裝說明,請參閱 適用於 .Net 的 Google Places Aggregate API 用戶端

設定驗證

使用用戶端程式庫時,您會使用應用程式預設憑證 (ADC) 進行驗證。如要瞭解如何設定 ADC,請參閱「提供應用程式預設憑證的憑證」。如要瞭解如何搭配用戶端程式庫使用 ADC,請參閱「使用用戶端程式庫進行驗證」。

使用用戶端程式庫

Java

import com.google.api.core.ApiFuture;
import com.google.maps.areainsights.v1.AreaInsightsClient;
import com.google.maps.areainsights.v1.ComputeInsightsRequest;
import com.google.maps.areainsights.v1.ComputeInsightsResponse;
import com.google.maps.areainsights.v1.Filter;
import com.google.maps.areainsights.v1.Insight;
import java.util.ArrayList;

public class AsyncComputeInsights {

  public static void main(String[] args) throws Exception {
    asyncComputeInsights();
  }

  public static void asyncComputeInsights() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (AreaInsightsClient areaInsightsClient = AreaInsightsClient.create()) {
      ComputeInsightsRequest request =
          ComputeInsightsRequest.newBuilder()
              .addAllInsights(new ArrayList<Insight>())
              .setFilter(Filter.newBuilder().build())
              .build();
      ApiFuture<ComputeInsightsResponse> future =
          areaInsightsClient.computeInsightsCallable().futureCall(request);
      // Do something.
      ComputeInsightsResponse response = future.get();
    }
  }
}

Go

// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Code generated by protoc-gen-go_gapic. DO NOT EDIT.

package areainsights_test

import (
	"context"

	areainsights "cloud.google.com/go/maps/areainsights/apiv1"
	areainsightspb "cloud.google.com/go/maps/areainsights/apiv1/areainsightspb"
)

func ExampleNewClient() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := areainsights.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	// TODO: Use client.
	_ = c
}

func ExampleNewRESTClient() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := areainsights.NewRESTClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	// TODO: Use client.
	_ = c
}

func ExampleClient_ComputeInsights() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := areainsights.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &areainsightspb.ComputeInsightsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/maps/areainsights/apiv1/areainsightspb#ComputeInsightsRequest.
	}
	resp, err := c.ComputeInsights(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Node.js

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Insights to compute. Currently only INSIGHT_COUNT and
 *  INSIGHT_PLACES are supported.
 */
// const insights = [1,2,3,4]
/**
 *  Required. Insight filter.
 */
// const filter = {}

// Imports the Areainsights library
const {AreaInsightsClient} = require('@googlemaps/areainsights').v1;

// Instantiates a client
const areainsightsClient = new AreaInsightsClient();

async function callComputeInsights() {
  // Construct request
  const request = {
    insights,
    filter,
  };

  // Run request
  const response = await areainsightsClient.computeInsights(request);
  console.log(response);
}

callComputeInsights();

Python

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.maps import areainsights_v1


async def sample_compute_insights():
    # Create a client
    client = areainsights_v1.AreaInsightsAsyncClient()

    # Initialize request argument(s)
    request = areainsights_v1.ComputeInsightsRequest(
        insights=['INSIGHT_PLACES'],
    )

    # Make the request
    response = await client.compute_insights(request=request)

    # Handle the response
    print(response)

.Net

using Google.Maps.AreaInsights.V1;
using System.Threading.Tasks;

public sealed partial class GeneratedAreaInsightsClientSnippets
{
    /// <summary>Snippet for ComputeInsightsAsync</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public async Task ComputeInsightsRequestObjectAsync()
    {
        // Create client
        AreaInsightsClient areaInsightsClient = await AreaInsightsClient.CreateAsync();
        // Initialize request argument(s)
        ComputeInsightsRequest request = new ComputeInsightsRequest
        {
            Insights =
            {
                Insight.Unspecified,
            },
            Filter = new Filter(),
        };
        // Make the request
        ComputeInsightsResponse response = await areaInsightsClient.ComputeInsightsAsync(request);
    }
}

其他資源