Thư viện ứng dụng API Bộ dữ liệu Maps

Trang này cho biết cách bắt đầu sử dụng thư viện ứng dụng cho API Tập dữ liệu Maps.

Đọc thêm về thư viện ứng dụng trong phần Giải thích về thư viện ứng dụng.

Cài đặt thư viện ứng dụng

Node.js

Để biết thêm thông tin, hãy xem bài viết Thiết lập môi trường phát triển Node.js.

npm install @googlemaps/maps-platform-datasets

Python

Để biết thêm thông tin, hãy xem bài viết Thiết lập môi trường phát triển Python.

pip install --upgrade google-maps-mapsplatformdatasets

Thiết lập phương thức xác thực

Khi dùng thư viện ứng dụng, bạn sẽ dùng Thông tin xác thực mặc định của ứng dụng (ADC) để xác thực. Để biết thông tin về cách thiết lập ADC, hãy xem phần Cung cấp thông tin xác thực cho Thông tin xác thực mặc định của ứng dụng. Để biết thông tin về cách sử dụng ADC với thư viện ứng dụng, hãy xem bài viết Xác thực bằng thư viện ứng dụng.

Sử dụng thư viện ứng dụng

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. Parent project that will own the dataset.
 *  Format: projects/{$project}
 */
// const parent = 'abc123'
/**
 *  Required. The dataset version to create.
 */
// const dataset = {}

// Imports the Mapsplatformdatasets library
const {MapsPlatformDatasetsClient} = require('@googlemaps/maps-platform-datasets').v1;

// Instantiates a client
const mapsplatformdatasetsClient = new MapsPlatformDatasetsClient();

async function callCreateDataset() {
  // Construct request
  const request = {
    parent,
    dataset,
  };

  // Run request
  const response = await mapsplatformdatasetsClient.createDataset(request);
  console.log(response);
}

callCreateDataset();

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 mapsplatformdatasets_v1


def sample_create_dataset():
    # Create a client
    client = mapsplatformdatasets_v1.MapsPlatformDatasetsClient()

    # Initialize request argument(s)
    request = mapsplatformdatasets_v1.CreateDatasetRequest(
        parent="parent_value",
    )

    # Make the request
    response = client.create_dataset(request=request)

    # Handle the response
    print(response)

Tài nguyên khác