When using the Google Places API, what is the difference between “using the JavaScript library” and “calling the API directly”?

I saw two forms of linking to the Google Places library / service using JavaScript, and I call the API directly, several times, but I don’t understand the difference. Google docs do not describe anything about the two ways to access the API.

For example, this question talks about two ways to access the API: OVER_QUERY_LIMIT in a loop

And it looks like there is a certain type of direct Internet access in this question: Querying the Google Places API using jQuery

Is this something where there was an old way related to formatting URL parameters and a new way using JavaScript library calls?

FINAL SUMMARY EDIT . There are two different ways to request data from Google, as described in @Dan Nissenbaum's answer below. And since my initial question, the QUERY_LIMIT question mentioned above has been edited to also include additional information about these two options.

+7
source share
2 answers

Perhaps you mean the difference between the Google Places API, which is intended for use on the SERVER server (i.e., using PHP to directly call the Google Places API), and the use of a completely different approach to the Google Places Javascript library in which BROWSER runs Javascript using the Javascript library provided by Google (which internally transfers calls to the Google Places API, so that you, as a Javascript programmer, need to understand the Javascript library provided by Google and use this)?

Here are two scenarios.

Scenario # 1: Use the API directly. For this method, you should refer to the Google API documentation for the Google Places API: https://developers.google.com/maps/documentation/places/ .

Using this API works as follows (just for a simple example). Suppose you want to get places at a distance of 1000 meters from latitude = -27.2531166, longitude = 138.8655664. You need to click the URL as described in the API documentation: https://developers.google.com/maps/documentation/places/#PlaceSearchRequests .

In this example, the URL looks like this (it's long):

https://maps.googleapis.com/maps/api/place/search/json?location=-27.2531166,138.8655664&radius=1000&sensor=false&key=AddYourOwnKeyHere 

You need a key for your personal use, which I believe you have. There are other parameters that you can specify, for example, limiting the results in restaurants, etc.

When you click this URL, the data will be returned in JSON or XML format, as indicated in the json text in the above URL (use xml text for xml). This data is returned exactly , since the data is returned from any URL when you click the URL in your browser.

You can verify this by simply typing the URL directly in your browser and see the results.

To use the API directly from the code, you will need to use the code that accesses the external URL above in the code and extracts the results inside the code (for example, using the PHP CURL library or using AJAX in Javascript).

Scenario number 2:. You are using the Javascript library provided by Google that wraps the API, so you don’t have to deal with it. I will talk about this in more detail if you do not know what it is.

+6
source

The documents discuss two different approaches. The Places library uses Google Places services in the Google Maps JavaScript API. If you use the Google Maps API in a browser, this is probably right for you: https://developers.google.com/maps/documentation/javascript/places

There is also a web service that allows you to directly request your application. You request it using direct HTTP calls on Google services. If you need access to data on your server or mobile device, this is the approach you want to take: https://developers.google.com/maps/documentation/places

+2
source

All Articles