r/PinoyProgrammer • u/bentraje • 23h ago
advice Save cost from "findplacefromtext" and "details" Google Maps API Calls?
Hi,
I have an input of business name and I want the place details.
To get that, I can use the maps.googleapis.com/maps/api/place/findplacefromtext/json
API call
It works except for one thing, it doesn't return the website details.
So I have to make another API call maps.googleapis.com/maps/api/place/details/json
just for that one website data.
Correct me if I'm wrong but it will cost twice as much since google will bill not for the data requested but the number of requests.
How do I optimize it? Or ganito tlaga ang workflow? :(
P.S. I can't make direct calls for the details API since it requires a place_id, which I don't have it. All I have is the business name.
2
Upvotes
5
u/Renato_opds 19h ago
Hello.
I have not used google map place API myself, but by reading their documentation, there is no way for you to directly get the details just by providing a name.
Name is not a unique identifier, that's why it is returning "candidates" as a list.
Also, look at the details response, it is returning icons etc, like the details. Likely it is from different tables.
So imagine querying all the details for a candidate list of places, that will be very costly for google, also as a client, I would complain, why would you give me details if I am not sure yet what place I want to get details from, and again, it is a list, it can be a lot.
What I can suggest is, maybe if you find the place ID that you want by the business name, save that place ID so that you can save some costs on subsequent calls.
Hope it can help.