You're all set!

To start developing, please head over to our developer documentation.

Activate the Google Places API for iOS

To get you started we'll guide you through the Google Developers Console to do a few things first:

  1. Create or choose a project
  2. Activate the Google Places API for iOS
  3. Create appropriate keys
Continue

Place IDs and Details

The Google Places API for iOS provides your app with rich information about places, including the place's name and address, the geographical location specified as latitude/longitude coordinates, the type of place (such as night club, pet store, museum), and more. To access this information for a specific place, you can use the place ID, a stable identifier that uniquely identifies a place.

Place details

The GMSPlace class provides information about a specific place. You can get hold of a GMSPlace object in the following ways:

The GMSPlace class provides the following information:

  • name – The place's name.
  • placeID – The textual identifier for the place. Read more about place IDs in the rest of this page.
  • coordinate – The geographical location of the place, specified as latitude and longitude coordinates.
  • openNowStatus – Indicates whether the place is open at the time when the request for place information is made.
  • phoneNumber – The place's phone number, in international format.
  • formattedAddress – The human-readable address of this location.

    Often this address is equivalent to the postal address. Note that some countries, such as the United Kingdom, do not allow distribution of true postal addresses due to licensing restrictions.

    The formatted address is logically composed of one or more address components. For example, the address "111 8th Avenue, New York, NY" consists of the following components: "111" (the street number), "8th Avenue" (the route), "New York" (the city) and "NY" (the US state).

    Do not parse the formatted address programmatically. Instead you should use the individual address components, which the API response includes in addition to the formatted address field.

  • rating – An aggregated rating of the place, returned as a float with values ranging from 1.0 to 5.0, based on aggregated user reviews.
  • priceLevel – The price level for this place, returned as an integer with values ranging from 0 (cheapest) to 4 (most expensive).
  • types – A list of place types that characterize this place. See the documentation for the supported types.
  • website – The URI of the place's website, if known. This is the website maintained by the business or other entity associated with the place.
  • attributions – An NSAttributedString containing the attributions that you must display to the user if your app uses place details retrieved from the Google Places API for iOS. For details on retrieving and displaying attributions, see the attributions guide.
  • addressComponents – An array of GMSAddressComponent objects representing components of the address for a place. These components are provided for the purpose of extracting structured information about a place's address, for example finding the city in which a place is located. Do not use these components for address formatting; instead, use the formattedAddress property, which provides a localized formatted address.

    Note the following facts about the addressComponents array:

    • The array of address components may contain more components than the formattedAddress.
    • The array does not necessarily include all the political entities that contain an address, apart from those included in the formattedAddress.
    • The format of the response is not guaranteed to remain the same between requests. In particular, the number of addressComponents varies based on the address requested and can change over time for the same address. A component can change position in the array. The type of the component can change. A particular component may be missing in a later response.

Get a place by ID

A place ID is a textual identifier that uniquely identifies a place. In the Google Places API for iOS, you can retrieve the ID of a place from a GMSPlace object. You can store the place ID and use it to retrieve the GMSPlace object again later.

To get a place by ID, call GMSPlacesClient lookUpPlaceID:callback:, passing a place ID and a callback method.

The API invokes the specified callback method, passing in a GMSPlace object. If the place is not found, the place object is nil.

Swift

// A hotel in Saigon with an attribution.
let placeID = "ChIJV4k8_9UodTERU5KXbkYpSYs"

placesClient.lookUpPlaceID(placeID, callback: { (place, error) -> Void in
  if let error = error {
    print("lookup place id query error: \(error.localizedDescription)")
    return
  }

  guard let place = place else {
    print("No place details for \(placeID)")
    return
  }

  print("Place name \(place.name)")
  print("Place address \(place.formattedAddress)")
  print("Place placeID \(place.placeID)")
  print("Place attributions \(place.attributions)")
})

Objective-C

// A hotel in Saigon with an attribution.
NSString *placeID = @"ChIJV4k8_9UodTERU5KXbkYpSYs";

[_placesClient lookUpPlaceID:placeID callback:^(GMSPlace *place, NSError *error) {
  if (error != nil) {
    NSLog(@"Place Details error %@", [error localizedDescription]);
    return;
  }

  if (place != nil) {
    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place placeID %@", place.placeID);
    NSLog(@"Place attributions %@", place.attributions);
  } else {
    NSLog(@"No place details for %@", placeID);
  }
}];

Display attributions in your app

When your app displays information obtained from GMSPlacesClient lookUpPlaceID:callback:, the app must also display attributions. See the documentation on attributions.

From our Terms of Service

Use Google data only
with Google Maps

If you use Google data, use it only with a Google Map. You can display Google data and data from other providers on a Google Map, just don't show Google data on a non-Google map.

Learn More

More about place IDs

The place ID used in the Google Places API for iOS is the same identifier as used in the Google Places API Web Service, Google Places API for Android and other Google APIs.

Each place ID can refer to only one place, but a single place can have more than one place ID. The most common case for handling multiple IDs for a place is when you've added a place that's initially scoped to your app, and later receives a Google-wide scope.

There are other circumstances which may cause a place to get a new place ID. For example, this may happen if a business moves to a new location.

When you request a place by specifying a place ID, you can be confident that you will always receive the same place in the response (if the place still exists). Note, however, that the response may contain a place ID that is different from the one in your request.

For more information, see the place ID overview.

Send feedback about...

location_on
Google Places API for iOS