-2

I would like to get the place_id based on the telephone. So far, I was able to get the place_id with the address but I wonder if I could get the same info but with the telephone.

import googlemaps 
gmaps = googlemaps.Client(key='API')


place_name = '3054 28th St, Boulder, CO 80304, Estados Unidos'
places_result = gmaps.places(place_name)
place_id = places_result['results'][0]['place_id']

Output

print(place['result']['place_id'])

ChIJFZ3Tw3vua4cRsd2Sia4hkLY

I want to get the same output but in the place_name I would like to get the telephone number and get the same place_id

place_result

    {'html_attributions': [],
 'results': [{'formatted_address': '3054 28th St, Boulder, CO 80301, USA',
   'geometry': {'location': {'lat': 40.0301734, 'lng': -105.2578728},
    'viewport': {'northeast': {'lat': 40.03152422989272,
      'lng': -105.2566366201073},
     'southwest': {'lat': 40.02882457010728, 'lng': -105.2593362798927}}},
   'icon': 'https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png',
   'icon_background_color': '#7B9EB0',
   'icon_mask_base_uri': 'https://maps.gstatic.com/mapfiles/place_api/icons/v2/generic_pinlet',
   'name': '3054 28th St',
   'place_id': 'ChIJs6f_tXvua4cRpmNh_22rOpc',
   'plus_code': {'compound_code': '2PJR+3V Boulder, Colorado, USA',
    'global_code': '85GP2PJR+3V'},
   'reference': 'ChIJs6f_tXvua4cRpmNh_22rOpc',
   'types': ['street_address']}],
 'status': 'OK'}
coding
  • 917
  • 2
  • 12
  • 25
  • 1
    Either I am misunderstanding your question or there isn't enough code here. We need to know what the value of places_result is in order to parse it. – Captain Caveman Apr 05 '22 at 21:59
  • 1
    In the documentation: [Find Place from Phone Number](https://developers.google.com/maps/documentation/javascript/places#find_place_from_phone_number) – geocodezip Apr 07 '22 at 00:01

1 Answers1

0

If you would like to get the Place IDs based on phone numbers, you can use Places Find Place API.

Here’s an example:

https://maps.googleapis.com/maps/api/place/findplacefromtext/json
  ?input=%2B16502530000
  &inputtype=phonenumber
  &key=YOUR_API_KEY

The input should be the phone numbers that are in international format (prefixed by a plus sign ("+"), followed by the country code, then the phone number itself. Next, use phonenumber as the inputtype. More information can be found here.

If you want to get the phone number in the result, you can use Places Details API. You just need the Place ID of the place you want to search, and add formatted_phone_number or the international_phone_number. Here’s an example:

https://maps.googleapis.com/maps/api/place/details/json
  ?fields=name%2Cformatted_phone_number%2Cinternational_phone_number
  &place_id=ChIJN1t_tDeuEmsRUsoyG83frY4
  &key=YOUR_API_KEY
Beth
  • 307
  • 1
  • 4