Table of Contents

TMS FNC Google Places — Guides

Set Request.Query for keyword searches and Request.Coordinate with Request.Radius for nearby searches. Handle OnGetPlaces to receive results.

Place detail lookup

Call GetPlaceDetails with a Google place ID to retrieve enriched data such as ratings, opening hours, and website URLs.

Place photos

Retrieve place photo URLs using GetPhotoURL with a photo reference from the search result's Photos collection.

From autocomplete suggestion to full place detail

Typeahead search UIs typically call GetAutoComplete on every keystroke to show a list of matching suggestions, then need the full place record only once the user picks one of them. Rather than requiring a separate step to extract and re-submit an identifier, GetPlaceDetail accepts a suggestion's TTMSFNCPlacesItem directly — the result item returned in a GetAutoComplete callback can be passed straight into GetPlaceDetail (or, alternatively, only its ID can be kept and passed as the place ID overload), avoiding an extra round trip to resolve the place ID before requesting details.

The snippet below fetches suggestions for a search string, then requests full details for the first suggestion once the autocomplete callback returns:

procedure TForm1.GetSuggestions(const ASearchText: string);
begin
  { Step 1: fetch autocomplete suggestions for the text the user typed. }
  TMSFNCGooglePlaces1.GetAutoComplete(ASearchText,
    procedure(const ARequest: TTMSFNCPlacesRequest; const ARequestResult: TTMSFNCCloudBaseRequestResult)
    begin
      if not ARequestResult.Success or (ARequest.Items.Count = 0) then
        Exit;

      { Step 2: pass a suggestion straight into GetPlaceDetail. The item }
      { itself (or its ID) is enough - no separate lookup is required.   }
      TMSFNCGooglePlaces1.GetPlaceDetail(ARequest.Items[0],
        procedure(const ADetailRequest: TTMSFNCPlacesRequest; const ADetailResult: TTMSFNCCloudBaseRequestResult)
        begin
          if not ADetailResult.Success or (ADetailRequest.Items.Count = 0) then
            Exit;

          ShowMessage(ADetailRequest.Items[0].Address + sLineBreak +
            ADetailRequest.Items[0].Phone + sLineBreak +
            ADetailRequest.Items[0].Website);
        end);

      { Alternatively, GetPlaceDetail also accepts the suggestion's place ID }
      { directly, which is useful when only the ID was cached or persisted: }
      // TMSFNCGooglePlaces1.GetPlaceDetail(ARequest.Items[0].ID);
    end);
end;

See also