react-native-google-places-autocomplete icon indicating copy to clipboard operation
react-native-google-places-autocomplete copied to clipboard

GooglePlaceData type is missing `terms` field

Open mehran75 opened this issue 9 months ago • 0 comments

Describe the bug

Seems like the type GooglePlaceData is missing the field terms. the terms is instead under StructuredFormatting which is not matched with the returned results.

Reproduction

types from react-native-google-places-autocomplete


interface StructuredFormatting {
  main_text: string;
  main_text_matched_substrings: Object[][];
  secondary_text: string;
  secondary_text_matched_substrings: Object[][];
  terms: Term[];
  types: PlaceType[];
}

interface GooglePlaceData {
  description: string;
  id: string;
  matched_substrings: MatchedSubString[];
  place_id: string;
  reference: string;
  structured_formatting: StructuredFormatting;
}

------------- my code -----------

function onConfirmAddress(data: GooglePlaceData, details: GooglePlaceDetail | null = null) {
        console.log(data.terms)
        console.log('-------------------------')
        console.log(data);
        console.log("-------------------------")
        // console.log(details);
    }
 (NOBRIDGE) LOG  [{"offset": 0, "value": "5th Avenue"}, {"offset": 12, "value": "Manhattan"}, {"offset": 23, "value": "New York"}, {"offset": 33, "value": "NY"}, {"offset": 37, "value": "USA"}]
 (NOBRIDGE) LOG  -------------------------
 (NOBRIDGE) LOG  {"description": "5th Avenue, Manhattan, New York, NY, USA", "matched_substrings": [{"length": 1, "offset": 0}, {"length": 9, "offset": 12}], "place_id": "Eig1dGggQXZlbnVlLCBNYW5oYXR0YW4sIE5ldyBZb3JrLCBOWSwgVVNBIi4qLAoUChIJ9Uc4naJYwokRSndBAbr7TVYSFAoSCWHmbgSPWMKJEYzA7PyBMgsK", "reference": "Eig1dGggQXZlbnVlLCBNYW5oYXR0YW4sIE5ldyBZb3JrLCBOWSwgVVNBIi4qLAoUChIJ9Uc4naJYwokRSndBAbr7TVYSFAoSCWHmbgSPWMKJEYzA7PyBMgsK", "structured_formatting": {"main_text": "5th Avenue", "main_text_matched_substrings": [[Object]], "secondary_text": "Manhattan, New York, NY, USA", "secondary_text_matched_substrings": [[Object]]}, "terms": [{"offset": 0, "value": "5th Avenue"}, {"offset": 12, "value": "Manhattan"}, {"offset": 23, "value": "New York"}, {"offset": 33, "value": "NY"}, {"offset": 37, "value": "USA"}], "types": ["route", "geocode"]}
 (NOBRIDGE) LOG  -------------------------

Additional context

  • Library Version: 2.5.7

  • React Native Version: 0.76.5

  • [x] iOS

  • [x] Android

  • [ ] Web

If you are using expo please indicate here:

  • [ ] I am using expo

More info

Google Places API doc: https://developers.google.com/maps/documentation/places/web-service/autocomplete#PlaceAutocompletePrediction

image image

mehran75 avatar Dec 31 '24 08:12 mehran75