尝试根据地址使用find_place获取商家名称

huangapple go评论69阅读模式
英文:

Trying to get business name based on address using find_place

问题

这只是我遇到问题的一个地点示例。我从返回中获取place_id,但当您实际输入返回的place_id时,它会显示附近的政府建筑,而不是加油站。我尝试了其他函数并限制了类型以获取更具体的信息,但这没有帮助。

import requests

url = "https://maps.googleapis.com/maps/api/geocode/json?address=203%20N%20Commerce%20ST%20Geneva%20AL&key=MY_KEY"

payload = {}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

我期望这将提供给我加油站的位置,而不是其他地方。这个place_id似乎是错误的:"place_id" : "ChIJCekaM2pGkogRwX3FIx8vFN8"

英文:

This is just an example of one of locations I'm having trouble with. I'm taking the place_id from the return to try and get more fields, but When you actually put in the place_id that it returns it gives government building nearby instead of the gas station. I've tried the other functions and limiting the types to more specifics, but that doesn't help.

import requests

url = " https://maps.googleapis.com/maps/api/geocode/json?      address=203%20N%20Commerce%20ST%20Geneva%20AL&key=MY_KEY"

payload={}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

I'm expecting this to give me the gas station location and not some other place. This place_id seems to be wrong "place_id" : "ChIJCekaM2pGkogRwX3FIx8vFN8"

答案1

得分: 1

Geocoding the Address of a Place will return a Place ID of the ADDRESS not the PLACE.

Since you are querying the address 203 N Commerce St Geneva, AL using the geocoder tool, of course, it would return the place ID of THAT SPECIFIC ADDRESS. The Geocoding API does not take ambiguous queries and it returns specific results from specific queries. So this explains why the Place ID: ChIJCekaM2pGkogRwX3FIx8vFN8 returns the address you queried instead of the Gas station name that you are looking for.

So to solve this, you need to specifically geocode the Place Name you want to get the Place ID. After querying the address you mentioned, I found out that the Gas Station Name is Geneva Citgo. So you could use that and it should look like this:

import requests

url = "https://maps.googleapis.com/maps/api/geocode/json?address=Geneva Citgo&key=API_KEY"

payload = {}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

With this, you will have ChIJp15WymtGkogRayP4w572um0 which is the exact Place ID of the gas station mentioned.

And please do note that Geocoding should not be used in finding a place.

Now to answer your main question...

How to get business name based on address using find_place?

As discussed above, since the address 203 N Commerce St Geneva, AL has its own Place ID, when you do a find_place query it will return the address itself. To solve this, you need to specifically mention what you're looking for. In this case, GAS STATIONS. So when you do a find_place query, you must specifically mention that you are looking for it, for example in this format: The_place_you_are_looking_for + address. The FindPlaceFromText endpoint is meant for "navigational" search only: queries that have a clear intent to find one place.

Therefore, your code should look like this:

import requests
url = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=gas station in 203 N Commerce St Geneva AL&inputtype=textquery&fields=formatted_address%2Cname%2Crating%2Copening_hours%2Cgeometry&key=API_KEY"

payload = {}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

Take note that the query specifically says what I want in this form: gas station in 203 N Commerce St Geneva AL. And with this, it will return the Place Name of the gas station that you are looking for, which is Geneva Citgo. (Up to you what fields you want to include though).

Ref to Find Place documentation for more information.

You can also use Text Search since the documentation specifically says:

"A Text Search returns information about a set of places based on a string — for example "pizza in New York" or "shoe stores near Ottawa" or "123 Main Street". The service responds with a list of places matching the text string and any location bias that has been set."

Ref to Text Search documentation for more information.

Hope this helps! Feel free to comment if this solves your issue or not.

英文:

Geocoding the Address of a Place will return a Place ID of the ADDRESS not the PLACE

Since you are querying the address 203 N Commerce St Geneva, AL using the geocoder tool, ofcourse it would return the place ID of THAT SPECIFIC ADDRESS. The Geocoding API does not take ambiguous queries and it returns specific results from specific queries. So this explains why the Place ID: ChIJCekaM2pGkogRwX3FIx8vFN8 returns the address you queried instead of the Gas station name that you are looking for.

So to solve this, you need to specifically geocode the Place Name you want to get the Place ID. After querying the address you mentioned, I found out that the Gas Station Name is Geneva Citgo. So you could use that and it should look like this:

import requests

url = " https://maps.googleapis.com/maps/api/geocode/json?address=Geneva Citgo&key=API_KEY"

payload = {}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

With this, you will have ChIJp15WymtGkogRayP4w572um0 which is the exact Place ID of the gas station mentioned.

And please do note that Geocoding should not be used in finding a place.

Now to answer your main question...

How to get business name based on address using find_place?

As discussed above, since the address 203 N Commerce St Geneva, AL have its own Place ID, when you do a find_place query it will return the address itself. To solve this, you need to specifically mention what you're looking for. In this case, GAS STATIONS. So when you do find_place query, you must specifically mention that you are looking for it, for example in this format: The_place_you_are_looking_for + address. The FindPlaceFromText endpoint is meant for "navigational" search only: queries that have a clear intent to find one place.

Therefore, your code should look like this:

import requests
url = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=gas station in 203 N Commerce St Geneva AL&inputtype=textquery&fields=formatted_address%2Cname%2Crating%2Copening_hours%2Cgeometry&key=API_KEY"

payload = {}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

Take note that the query specifically says what I want in this form: gas station in 203 N Commerce St Geneva AL. And with this, it will return the Place Name of the gas station that you are looking for which is Geneva Citgo. (Up to you what fields you want to include though).

Ref to Find Place documentation for more information.

You can also use Text Search since the documentation specifically says:
>"A Text Search returns information about a set of places based on a string — for example "pizza in New York" or "shoe stores near Ottawa" or "123 Main Street". The service responds with a list of places matching the text string and any location bias that has been set."

Ref to Text Search documentation for more information.

Hope this helps! Feel free to comment if this solves your issue or not.

huangapple
  • 本文由 发表于 2023年3月23日 09:56:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75818689.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定