Get a business' name with Google Maps API
Asked Answered
T

2

5

Inverse to most location querying efforts, I am actually trying to identify a business' name with Google APIs by either its address or Google placeid. e.g., when I search for 1625 Wilshire Blvd, Los Angeles, CA 90017 on googlemaps.com, its results show me that "at this location" is "McDonald's".

However, when making the API call with the following URL, the name comes up as the street address, when what I want is to identify the business' name at that location ("McDonald's"):

https://maps.googleapis.com/maps/api/place/textsearch/json?query=1625%20Wilshire%20Blvd,%20Los%20Angeles,%20CA%2090017&sensor=false&key=<api_key>

EDIT: Using the exact call that @xomena recommended, I'm still having the same issue. I've run it both R and Python and the result I’m getting is the street address in place of the name with both ways.

R Code:

packages <- c("RJSONIO")
new_packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new_packages)) install.packages(new_packages)

library(RJSONIO)

fromJSON(URLencode(paste("https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=1625%20Wilshire%20Blvd%2C%20Los%20Angeles%2C%20CA%2090017&inputtype=textquery&fields=formatted_address,name,place_id&key=", api_key, sep = "")))

R Output:

$candidates
$candidates[[1]]
                               formatted_address 
"1625 Wilshire Blvd, Los Angeles, CA 90017, USA" 
                                            name 
                            "1625 Wilshire Blvd" 
                                        place_id 
                   "ChIJ18AW_aPHwoARXRm-cgcRcDs" 


$debug_log
$debug_log$line
list()


$status
[1] "OK"

Python Code:

import requests

requests.get("https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=1625%20Wilshire%20Blvd%2C%20Los%20Angeles%2C%20CA%2090017&inputtype=textquery&fields=formatted_address,name,place_id&key="+API_KEY).json()

Python Output:

{'candidates': [{'formatted_address': '1625 Wilshire Blvd, Los Angeles, CA 90017, USA', 'name': '1625 Wilshire Blvd', 'place_id': 'ChIJ18AW_aPHwoARXRm-cgcRcDs'}], 'debug_log': {'line': []}, 'status': 'OK'}

Twirl answered 17/9, 2018 at 17:26 Comment(1)
If you want the placeid of a location, try nearbysearch (with the location)Medicament
O
4

Maybe you can get business name by using Google Place Autocomplete requests:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=601%20East%20Kennedy%20Blvd,%20Tampa,%20FL,%20USA&types=establishment&language=en&key=YOUR_API_KEY

I get the following response:

{"predictions":[
  {
     "description" : "Quest Diagnostics Inside New Castle Walmart Store, 117 Wilton Blvd, New Castle, DE 19720, USA",
     "id" : "8295289e301fd05ae69a8d3cd8d25da31c29c66d",
     "matched_substrings" : [
        {
           "length" : 10,
           "offset" : 25
        },
        {
           "length" : 11,
           "offset" : 55
        },
        {
           "length" : 2,
           "offset" : 80
        },
        {
           "length" : 5,
           "offset" : 83
        },
        {
           "length" : 3,
           "offset" : 90
        }
     ],
     "place_id" : "ChIJtTv6_PsHx4kRYZZtvcrallQ",
     "reference" : "ChIJtTv6_PsHx4kRYZZtvcrallQ",
     "structured_formatting" : {
        "main_text" : "Quest Diagnostics Inside New Castle Walmart Store",
        "main_text_matched_substrings" : [
           {
              "length" : 10,
              "offset" : 25
           }
        ],
        "secondary_text" : "117 Wilton Blvd, New Castle, DE 19720, USA",
        "secondary_text_matched_substrings" : [
           {
              "length" : 11,
              "offset" : 4
           },
           {
              "length" : 2,
              "offset" : 29
           },
           {
              "length" : 5,
              "offset" : 32
           },
           {
              "length" : 3,
              "offset" : 39
           }
        ]
     },
     "terms" : [
        {
           "offset" : 0,
           "value" : "Quest Diagnostics Inside New Castle Walmart Store"
        },
        {
           "offset" : 51,
           "value" : "117 Wilton Blvd"
        },
        {
           "offset" : 68,
           "value" : "New Castle"
        },
        {
           "offset" : 80,
           "value" : "DE"
        },
        {
           "offset" : 83,
           "value" : "19720"
        },
        {
           "offset" : 90,
           "value" : "USA"
        }
     ],
     "types" : [ "health", "point_of_interest", "establishment" ]
  }],"status" : "OK"}

I think predictions[0].description has business name.

But not every time the response is returned. The response's predictions may be an empty array.

Obadias answered 28/6, 2020 at 9:39 Comment(0)
P
2

I believe the Find place endpoind is doing what you are looking for

When I execute the following request

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=1625%20Wilshire%20Blvd%2C%20Los%20Angeles%2C%20CA%2090017&inputtype=textquery&fields=formatted_address,name,place_id&key=MY_API_KEY

I get the following response

{
  "candidates":[
    {
      "formatted_address":"1625 Wilshire Blvd, Los Angeles, CA 90017, USA",
      "name":"McDonald's",
      "place_id":"ChIJ0QBm-6PHwoARpfbcollvKIc"
    }
  ],
  "debug_log":{
    "line":[
    ]
  },
  "status":"OK"
}

As you can see the Find place returns McDonald's business.

I hope this helps!

Update

Interesting. Do you know by chance where is located your server? As you can see in the documentation, by default find place uses IP address bias. My server is located in the US and I get McDonald's, if your server IP address is from different area you can get a different results due to location biasing. In this case I can suggest specifying an area to bias your results, for example define circle or rectangle area. The request should be similar to

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=1625%20Wilshire%20Blvd%2C%20Los%20Angeles%2C%20CA%2090017&inputtype=textquery&fields=formatted_address,geometry,name,place_id&locationbias=circle%3A100%4034.0559572%2C-118.2708558&key=YOUR_API_KEY

Prestidigitation answered 17/9, 2018 at 22:11 Comment(1)
thanks for the response. please see my question's edit.Twirl

© 2022 - 2024 — McMap. All rights reserved.