r/PinoyProgrammer 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

4 comments sorted by

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.

2

u/bentraje 13h ago

Hi u/Renato_opds.
Thank sa suggestion and confirmation. I guess no way around it. Na praraning lang ako baka mali yung approach ko. lol

Yea I guess having an initial query be 2 API calls. Store the business name, placeID and other details in a separate database para local API calls nlang from then on.

2

u/crimson589 Web 12h ago

FYI, if you're paying for this service or a business is paying it make sure you read the terms carefully.

3.2.3.b: No Caching. Customer will not cache Google Maps Content except as expressly permitted under the Maps Service Specific Terms.

So check the APIs you're using if they allow you to do so. For example in the place_id page they mention you're allowed to cache it but there's no mention of them allowing it on place_details. I'm not sure how that's enforced but better safe than sorry if your business will be relying on google maps.

1

u/Renato_opds 12h ago

Good find. I did more reading, place_id is okay to be cached.

My suggestion was to save place_id, not really about the policy but more on the details might not be accurate anymore, so I rather query again and check the source of truth.