Google places autocomplete from client-side app - google-maps

Anyone wise to whether it is possible to use the google places autocomplete api from a client side app.
I tried to access it with a jsonp request to the following url..
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=#{input}&types(regions)&language=en_en&key=MY_API_KEY&callback=JSONP_CALLBACK"
And I get this response
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 94.33.38.138, with referer: http://localhost:3000/"
What I'm finding out is that the autocomplete api requires a server key, and can only be accessed from the backend. Is that correct? Or is there another way to access it from a browser?
I need to combine the results from the places autocomplete with another autocomplete list on the same input field so the google places autocomplete widget is not an option.

You may request the predictions via the autocomplete-service of the places-library of the javascript-API( https://developers.google.com/maps/documentation/javascript/places-autocomplete#place_autocomplete_service )...no key is required and it may be requested from client-side

Related

Access denied for map geocode api [duplicate]

I'm trying to program geocoding. I created API key, but when I add it into my website code I don't get anything, however when I don't use API everything works well. When I'm sending:
https://maps.googleapis.com/maps/api/geocode/json?address=".$adres."&key=KLUCZ_XXX
I get a response:
Browser API keys cannot have referer restrictions when used with this API.
If I use:
https://maps.googleapis.com/maps/api/geocode/json?address=".$adres"
The result is correct but the number of queries is limited per day.
Key constraint: referrals HTTP (Web) - set to the domain from which conjure inquiry. Interface Google Maps Geocoding API is turned on.
Does the API key has to be activated also somewhere else to work?
It sounds like you may be making the API call server side. I ran into this issue earlier today. Since you've placed a referrer restriction on your API key, it will be limited to executing on the browser with the web service APIs, including the Geocoding API. It didn't work for me even when manually setting the referrer in the request headers. You can find the other web service APIs on this page: https://developers.google.com/maps/web-services/
Important: If you are using any of the web service APIs with an API key that has referer restictions, your requests will fail with the error message: "API keys cannot have referer restrictions when used with this API." You should switch to using a server restriction.
You'll want to create a separate key to use server-side. You can change your restriction from a browser restriction to a server restriction by using IP addresses to restrict access, instead of browser referrers.
See this section in the Maps APIs FAQ on switching key type to a server restricted key: https://developers.google.com/maps/faq#switch-key-type
Alternatively, you can continue using a browser key and geocode client-side (JavaScript), then return the result to the backend via ajax.
If server-side geocoding is not an option, you should use the geocoder from the Google Javascript API. You can set HTTP referer restrictions on that API.
Google itself says to avoid the Non-Javascript Geocoder API for dynamic geocoding:
This service is generally designed for geocoding static
(known in advance) addresses for placement of application content on a
map; this service is not designed to respond in real time to user
input. For dynamic geocoding (for example, within a user interface
element), consult the documentation for the Maps JavaScript API client
geocoder and/or the Google Play services Location APIs.
This issue happens when you set the referrer for the server key to the domain name instead of the IP address, then it will show this message -
API keys with referer restrictions cannot be used with this API
.
For geocode API create a separate API key and restrict that API using IP address.
It worked for me.

Which Google Maps API to enable to get http get to work

I want to use this get in order to get Lat/Long for an address.
Currently, it always returns REQUEST_DENIED. This API project is not authorized to use this API.
I have ensured that my key is enabled, and currently, it has no restrictions for testing purposes. This is the url, with the actual key replaced with 12345.
https://maps.googleapis.com/maps/api/geocode/xml?address=123%2C%20Harbor%2C%20Woods%20Circle%2C%20Safety%2C%20Harbor%2C%20FLCA%2C%2034695&key=12345
I have tried Disabling the Google Maps API, and then Enabling it again, but I still get the same error message.
I am thinking that maybe I don't have the right API enabled on this, as it should be working.
To use the Geocoding Web Service you need to enable it in the Google API Console
I just found it, I needed to enable the Geocoding API.

Google Maps API is never satisfied

If I use URL referrer authentication with Geocoding API it says:
There was an error while trying to fix the Venues geolocation information: API keys with referer restrictions cannot be used with this API.
Which after research I find that this means that Google Maps is looking for IP address authentication.
But if I use IP address authentication with Javascript Maps API it says:
JavaScript API error: RefererNotAllowedMapError
https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error
Your site URL to be authorized: https://example.com
What can be going on?
How can I fully satisfy the good ol'Google Maps?
It looks like you're using two different Maps APIs; the client-side JavaScript API and the server-side Geocoding API web service. This means you need 2 API keys; one restricted with HTTP referrers for client-side use, and the other one restricted by IP address for web services only.
To learn more on how API key restrictions work check out Google's documentation on API key best practices.
Hope this helps!
I know this is 3 months old now. But I had the same problem and I found out how to solve this.
As evan said, you need 2 API Keys. And annoyingly, The Events Calendar only have one field for the API Key.
BUT, I found a link here: https://support.theeventscalendar.com/ to https://support.theeventscalendar.com/716190-Using-Google-Maps-API-Key-Restrictions. The page redirects though... But I managed to screen shot parts of it before it redirects and found this snippet: https://gist.github.com/cliffordp/a2ec320313afbc1ffb5f0e5ac654b7fb
(I changed the code to use a define instead because I don't want my API key in git)
This filter will make it possible to have two API KEYS.

Google Static Maps rejects requests for some domains

On some domains Google Maps returns instead of image this error message: The Google Maps Platform server rejected your request. You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account
Domains where it does not work:
http://en.aston-martin-club.com/test_mapa.php
http://en.ktm-club.cz/test_mapa.php
Domains where it works:
http://en.renault-club.cz/test_mapa.php
http://en.lada-club.eu/test_mapa.php
The image I display on web is from http://maps.googleapis.com/maps/api/staticmap URL. It is Google Maps Stati API https://developers.google.com/maps/documentation/maps-static/intro
Why on some domains it works and some not? If it wil not work for any domain, then I think I need to add "key=YOUR_API_KEY" parameter.
I spent many hours trying to find out the reason, but did not succeeded. Any help is very welcome.
In the past (and this is probably still the case), domains that were using the API before keys became required were "grandfathered" with keyless access (they will work without a key).
Keys are now required, so regardless whether the domains "work" without keys or not, it is best to add a valid key to the request.
The things that determine whether or not the domains are "grandfathered" to keyless access are:
When the domain was created
When the domain started using the Google Maps APIs
Google rejects all the requests for static images that does not include api key in URL.
I don't know Google's threshold, but en.aston-martin-club.com is blocked by Google obviously. You must include api key in URL at least.

Google maps geocoding API inconsistent

I have a server application that calls the google maps geocoding API at http://maps.googleapis.com/maps/api/geocode/json
I experience that when the server application invokes such an URL, the response is sometimes ZERO_RESULTS.
If I take the exact same URL and paste in a browser, I get a valid result back.
Any ideas to what differences can cause this? HTTP headers? Something else?
In the link you provided it is missing the address, components, latlng or place_id parameters, besides the Google Map API KEY.
You need at least one of the parameters and the Key to get a proper response.
e.g.
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ1xwGTLE1K4gRmzFDd_1HzPc&key=xxx
Just add your KEY and it should work.