Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

javascript - Google Place search, text search, and nearby search don't return certain exact matches

I'm trying to return google places with a given name and location. Google Places API has 3 options for searching for places:

  • Find Place
  • Nearby Search
  • Text Search

I tried all 3 endpoints, but certain places never get returned even when the query string exactly matches what I see on Google Maps

Example 1:

Searching for "VIK Hotel San Antonio" with Find Place API

URL: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=VIK Hotel San Antonio&inputtype=textquery&fields=photos,formatted_address,name,place_id&locationbias=circle:3000@28.9215,-13.64163&key={{google_key}}&type=lodging&rankby=distance&language=en

Params:
input:VIK Hotel San Antonio
inputtype:textquery
fields:photos,formatted_address,name,place_id
locationbias:circle:3000@28.9215,-13.64163
key:{{google_key}}
type:lodging
rankby:distance
language:en

Returns:

{
    "candidates": [
        {
            "formatted_address": "Av. de las Playas, 88, 35510 Puerto del Carmen, Las Palmas, Spain",
            "name": "Hotel Las Costas",
            "photos": [
                {
                    "height": 560,
                    "html_attributions": [
                        "<a href="https://maps.google.com/maps/contrib/112252274241085829382">A Google User</a>"
                    ],
                    "photo_reference": "ATtYBwIXdPlny9tLx8nEdYX2VOF-0J6QKZQl2UroHiOnBGYnwCEFhBHx41JFsKQH_q-bZRq7V0Vmo_RuB-0hMu2S9BPB7uyrL4_fOMxEehcRSjgAY3KZOkvQ_yKfli_Z_L86iLbyZxLT4K5kNGLo2bnEilUqsUNOz2J2Mf9IgMIIB2EsWmn8",
                    "width": 800
                }
            ],
            "place_id": "ChIJ0_jBN-QlRgwRZaZhj7c4zgM"
        }
    ],
    "status": "OK"
}

There's only 1 result returned, but that's not the correct place. It's another hotel nearby. If we look at Google Maps however, we can see a result with exactly the name I was looking for: VIK Hotel San Antonio on Google Maps

I've noticed that this is happening with a significant number of the searches I'm making.

Other examples:

Text Search API:

URL: https://maps.googleapis.com/maps/api/place/textsearch/json?query=vik hotel san antonio&location=28.9215,-13.64163&radius=3000&key={{google_key}}&type=lodging&region=us

Params:
query:vik hotel san antonio
location:28.9215,-13.64163
radius:3000
key:{{google_key}}
type:lodging
region:us

Nearby Search API:

URL: https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=28.9215,-13.64163&radius=3000&keyword=VIK Hotel San Antonio&key={{google_key}}

Params:
location:28.9215,-13.64163
radius:3000
keyword:VIK Hotel San Antonio
key:{{google_key}}

Both of the above exampels returned a result for the same incorrect place.

I also tried the autocomplete API:

URL: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=VIK Hotel San Antonio&location=28.9215,-13.64163&origin=28.9215,-13.64163&radius=3000&key={{google_key}}&strictbounds

Params:
input:VIK Hotel San Antonio
location:28.9215,-13.64163
origin:28.9215,-13.64163
radius:3000
key:{{google_key}}
strictbounds:

Returns:

{
    "predictions": [
        {
            "description": "Oasis san Antonio, Avenida de las Playas, Tías, Spain",
            "distance_meters": 185,
            "matched_substrings": [
                {
                    "length": 11,
                    "offset": 6
                }
            ],
            "place_id": "ChIJf3Nr-EAlRgwRZOOH9wrpdAQ",
            "reference": "ChIJf3Nr-EAlRgwRZOOH9wrpdAQ",
            "structured_formatting": {
                "main_text": "Oasis san Antonio",
                "main_text_matched_substrings": [
                    {
                        "length": 11,
                        "offset": 6
                    }
                ],
                "secondary_text": "Avenida de las Playas, Tías, Spain"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "Oasis san Antonio"
                },
                {
                    "offset": 19,
                    "value": "Avenida de las Playas"
                },
                {
                    "offset": 42,
                    "value": "Tías"
                },
                {
                    "offset": 48,
                    "value": "Spain"
                }
            ],
            "types": [
                "lodging",
                "point_of_interest",
                "establishment"
            ]
        },
        {
            "description": "Wok San Antonio, Avenida de las Playas, Puerto del Carmen, Spain",
            "distance_meters": 275,
            "matched_substrings": [
                {
                    "length": 11,
                    "offset": 4
                }
            ],
            "place_id": "ChIJr5WokR0lRgwRb70lhPAPaSA",
            "reference": "ChIJr5WokR0lRgwRb70lhPAPaSA",
            "structured_formatting": {
                "main_text": "Wok San Antonio",
                "main_text_matched_substrings": [
                    {
                        "length": 11,
                        "offset": 4
                    }
                ],
                "secondary_text": "Avenida de las Playas, Puerto del Carmen, Spain"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "Wok San Antonio"
                },
                {
                    "offset": 17,
                    "value": "Avenida de las Playas"
                },
                {
                    "offset": 40,
                    "value": "Puerto del Carmen"
                },
                {
                    "offset": 59,
                    "value": "Spain"
                }
            ],
            "types": [
                "restaurant",
                "food",
                "point_of_interest",
                "establishment"
            ]
        },
        {
            "description": "HiperDino Express SAN ANTONIO, Avenida de las Playas, Tías, Spain",
            "distance_meters": 126,
            "matched_substrings": [
                {
                    "length": 11,
                    "offset": 18
                }
            ],
            "place_id": "ChIJsWi4kZQlRgwRjapantbE8fM",
            "reference": "ChIJsWi4kZQlRgwRjapantbE8fM",
            "structured_formatting": {
                "main_text": "HiperDino Express SAN ANTONIO",
                "main_text_matched_substrings": [
                    {
                        "length": 11,
                        "offset": 18
                    }
                ],
                "secondary_text": "Avenida de las Playas, Tías, Spain"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "HiperDino Express SAN ANTONIO"
                },
                {
                    "offset": 31,
                    "value": "Avenida de las Playas"
                },
                {
                    "offset": 54,
                    "value": "Tías"
                },
                {
                    "offset": 60,
                    "value": "Spain"
                }
            ],
            "types": [
                "supermarket",
                "grocery_or_supermarket",
                "food",
                "point_of_interest",
                "store",
                "establishment"
            ]
        },
        {
            "description": "Bus stop San Antonio, Puerto del Carmen, Spain",
            "distance_meters": 32,
            "matched_substrings": [
                {
                    "length": 11,
                    "offset": 9
                }
            ],
            "place_id": "ChIJC7ejPeElRgwRtwVyDTOBAcU",
            "reference": "ChIJC7ejPeElRgwRtwVyDTOBAcU",
            "structured_formatting": {
                "main_text": "Bus stop San Antonio",
                "main_text_matched_substrings": [
                    {
                        "length": 11,
                        "offset": 9
                    }
                ],
                "secondary_text": "Puerto del Carmen, Spain"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "Bus stop San Antonio"
                },
                {
                    "offset": 22,
                    "value": "Puerto del Carmen"
                },
                {
                    "offset": 41,
                    "value": "Spain"
                }
            ],
            "types": [
                "point_of_interest",
                "establishment"
            ]
        }
    ],
    "status": "OK"
}

Which again, doesn't have the correct place in the list. I suspected that maybe the place is generated on demand and doesn't actually have a Google Place ID, but that seems very remote to me and I was not able to confirm this. There's a Places API Finder tool that allows you to search for a place and retrieve its ID, but it uses the autocomplete API for searching places. Since the place I'm looking for is not returned by the autocomplete API, I cannot obtain the Google Place ID


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...