Ссылка на Google Карты

The Places API (New) accepts requests for place data through a variety of methods. The Places API (New) response contains data about a place, including location data and imagery, geographic locations, and prominent points of interest.

The response from Text Search (New), Nearby Search (New), and Place Details (New) can also contain links to Google Maps. Your users can browse to these Google Maps links to see additional information about a place in the response.

For example, you search for airports in San Francisco, California. The response then includes San Francisco International Airport (SFO) in the list of places. The Place object for SFO in the response adds the googleMapsUri field containing Google Maps links to open Google Maps to the place, directions to the place, reviews of the place, and place photos.

Along with the links added to the Place object, the googleMapsUri field is also added to the Reviews and Photos objects in the response:

  • Reviews.googleMapsUri : Contains a Google Maps link to the review so you can view it in a browser.

  • Photos.googleMapsUri : Contains a Google Maps link to the photo so you can view it in a browser.

The API Explorer lets you make live requests so that you can get familiar with these new options:

Попробуйте!

The following table shows the Google Maps links that you can include in the response:

ссылка на Google Maps Описание Название поля
Место Ссылка для открытия этого места на Google Maps. googleMapsLinks.placeUri
Направления Link to open directions to the place in Google Maps. googleMapsLinks.directionsUri
Написать отзыв Link to write a review for the place in Google Maps. googleMapsLinks.writeAReviewUri
Читать отзывы Ссылка для просмотра отзывов об этом месте на Google Maps. googleMapsLinks.reviewsUri
Фотографии Ссылка для просмотра фотографий этого места на Google Maps. googleMapsLinks.photosUri

The links in the places response are contained in the googleMapsLinks field. Make sure to include the googleMapsLinks field in the field mask of the request if you want them to appear in the response.

For example, the following Text Search (New) includes all Maps links in the response:

curl -X POST -d '{
  "textQuery" : "San Francisco International Airport"
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \
-H 'X-Goog-FieldMask: places.displayName,places.formattedAddress,places.priceLevel,places.googleMapsLinks' \
'https://places.googleapis.com/v1/places:searchText'

Ответ представлен в следующем виде:

{
  "places": [
    {
      "formattedAddress": "San Francisco, CA 94128, USA",
      "displayName": {
        "text": "San Francisco International Airport",
        "languageCode": "en"
      },
      "googleMapsLinks": {
        "placeUri": "https://maps.google.com/?cid=11885663895765773631",
        "directionsUri": "https://www.google.com/maps/dir//''/data=!4m7!4m6!1m1!4e2!1m2!1m1!1s0x808f778c55555555:0xa4f25c571acded3f!3e0",
        "writeAReviewUri": "https://www.google.com/maps/place//data=!4m3!3m2!1s0x808f778c55555555:0xa4f25c571acded3f!12e1",
        "reviewsUri": "https://www.google.com/maps/place//data=!4m4!3m3!1s0x808f778c55555555:0xa4f25c571acded3f!9m1!1b1",
        "photosUri": "https://www.google.com/maps/place//data=!4m3!3m2!1s0x808f778c55555555:0xa4f25c571acded3f!10e5"
      }
    }
  ]
}

You don't have to return all links in the response. For example, if you only want the photos link in the response, modify the field mask as shown below to only include the photosUri field:

curl -X POST -d '{
  "textQuery" : "San Francisco International Airport"
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \
-H 'X-Goog-FieldMask: places.displayName,places.formattedAddress,places.priceLevel,places.googleMapsLinks.photosURI' \
'https://places.googleapis.com/v1/places:searchText'

Включите указания в ответ.

All Places methods support the generation of the directions link in the response. The current location is used as the origin, the place location is used as the destination, and the travel mode is drive.

The next example uses Nearby Search (New) to include the maps directions link in the response in the directionsUri field:

curl -X POST -d '{
  "includedTypes": ["restaurant"],
  "maxResultCount": 10,
  "locationRestriction": {
    "circle": {
      "center": {
        "latitude": -33.8688,
        "longitude": 151.1957362},
      "radius": 500.0
    }
  }
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key:API_KEY' \
-H 'X-Goog-FieldMask: places.displayName,places.googleMapsLinks.directionsUri' \
https://places.googleapis.com/v1/places:searchNearby

This release adds the googleMapsUri field to the Reviews and Photos objects in the response. Browsing to these links opens the review or photo in Google Maps.

For example, the following Text Search (New) includes reviews and photos for each place in the response:

curl -X POST -d '{
  "textQuery" : "Spicy Vegetarian Food in Sydney, Australia"
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \
-H 'X-Goog-FieldMask: places.displayName,places.reviews,places.photos' \
'https://places.googleapis.com/v1/places:searchText'

In the response, each element of the reviews and photos array contains the googleMapsUri field to open the review or photo in a browser.

Попробуйте!

The API Explorer lets you make sample requests so that you can get familiar with the API and the API options.

  1. Select the API icon on the right side of the page.

  2. Optionally expand Show standard parameters and set the fields parameter to the field mask .

  3. При желании можно отредактировать текст запроса .

  4. Select Execute button. In the dialog, choose the account that you want to use to make the request.

  5. В панели API Explorer выберите

    Для развертывания окна API Explorer разверните его на весь экран .