Geocode mapping - a couple of questions - google-maps

A couple of troubleshooting questions regarding Geocode mapping.
One, it is problematic doing Geocode mapping in IE ( I use version 11), as a JSON error results, even tough the mapping itself seems to work, but with the error "Unable to get the property 'sa' of undefined or null reference. Is there some sort of setting in IE that prevents this? Or is it just a matter of using a different browser, which never seem to have this error? No skin off my nose, but a lot of my customers use IE and I'm hoping to avoid telling them to switch.
Also, Geocoding makes use of the API Key, of course. I have this key embedded in my javascript. Is this a safe practice, or do these keys ever "expire" for lack of a better term? I'm trying to avoid the potential problem of the geocoding suddenly failing to work.
Thanks

Do you have Compatibility View on? It's not supported by the Maps JS API. If that's not it, maybe post the part of your javascript that's throwing the error.
As far as your keys - you should be able to restrict the key in the Google API console (Console > Credentials > click the key name) - in your case it's probably best to use HTTP referrers and set your website's domain

Related

Github Automerge Failure Notification (API v4 GraphQL mutation enablePullRequestAutoMerge)

at my company we want to make use of the relatively new API feature "Automerge" (not through a UI but through an API call),
However we can't seem to find any documentation of a webhook (or other asyc way) of finding out if a merge request failed and why,
anyone know a way to receive such a notification?
Thanks! :)
Hope this saves some work for someone out there,
we asked Github.com support directly and they said there was no async / webhooky way of doing this (as of Nov 2021).
Here's a quote from the support person when asked if there were a way to find out, here's what they wrote:
There wouldn't be a great way to discern that (reason for failure) and
it may be better when you see that, to use the REST API to Get the
Pull Request to get some additional information.
looking at the documentation as suggested in the quote above it seems that through the "closed" action and "merged" key one could discern whether a merge was successful or not, but without any further information about the failure.

Google places API RefererNotAllowedMapError

I know I have to set the credentials I have done so, I have waited about half an hour between credential change, I've tried many domains, ports, and I still get the RefererNotAllowedMapError
These are the values I've set in my API key credentials properties:
https://gist.github.com/onzag/23b01979d9bd99c749d8a998c4fa841d
I've tried no value at all, I've tried even an open api key with no restrictions at all (which gives a different error and says that it's expired); I've created a couple of dozen api keys with different combinations, no luck.
I've tried exact paths, without wildcards, different domains, I've removed the protocol; I've read every single trick I can find online and nothing does the job.
Does anyone have an idea? Do I need to create a new developer account?...
I figured it out for anyone else struggling with a impossible to fix RefererNotAllowedMapError, it has nothing to do with your credentials, at all, you are forced to enable google maps javascript API even if the development guide says that places is an independent API from maps.
The error is totally misleading there's nothing wrong with your credentials.

Odd responses using Google Maps Geocode Lookup (API key)

I've been working with website that uses geocode lookups via Google. I've been testing this for awhile now.
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Pennsylvania+Ave+NW,+Washington,+DC&key=XXXXXXXXXXXXXXXXXXXXXXXXXXX
I've got that key locked to particular servers. All of a sudden I'm seeing geocode lookup errors. The response back from Google is:
{
error_message: "Browser API keys cannot have referer restrictions when used with this API.",
results: [ ],
status: "REQUEST_DENIED"
}
When I try a simple request without the API key at all it seems to work fine. Here you can try this yourself. Copy and paste the next line in your browser's URL and return.
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Pennsylvania+Ave+NW,+Washington,+DC
Now, I probably shouldn't look a gift horse in the mouth, but the whole thing seems odd. If I remove my API keys today, will my websites, that rely on an address to Lat/Lng conversion, all fail tomorrow?
Is anybody else experiencing odd failures with Google Maps and GeoCode lookups? Is anyone aware of a systemic content or policy change from the Google mapping / GeoCoding team??
Edit, update:
So this defect lasted about 40 minutes, from around 9:10PM PST until a bit before 10PM PST. It seems to be fixed now.
Response to comment: Hmmm. I've been looking at the API keys as:
Server keys: Create and use a Server key if your application runs on a
server. Do not use this key outside of your server code. For example,
do not embed it in a web page. To prevent quota theft, restrict your
key so that requests are only allowed from your servers' source IP
addresses.
Browser keys: Create and use a Browser key if your application runs on
a client, such as a web browser. To prevent your key from being used
on unauthorized sites, only allow referrals from domains you
administer.
I'm definitely doing this complete lookup from user directly to Google without a server in the middle. No way can I safely use a Server key there. So I've read your input, and it definitely says Server key for geocoding. But, that really implies that no one should ever allow a browser / client interaction to process a geocode lookup. Frankly I just assumed the writeup was out of date and a bit inaccurate.
While you may be right, the whole thing just looks odd. I would have thought that if Geocode required a lookup from a server (only) and never from a web application via the browser (ever) that there would have been some direct comment as to that effect.
Oh, and the browser keys, with server fencing, seem to be working again. Again, I'm just saying the whole thing is odd. I'm treating this as a temporary hiccup up at the Google geocode servers.
And yes, I can certainly introduce an API server for a round trip Ajax call to do the lookup safely with a server key, but what's the point? Is there a benefit that I'm just not seeing? I guess I could add elements like a nonce to protect my round trip geocode intermediate lookup server from somebody else using it, etc.... But at this point, I'm just confused.
Update #2: 16 Jun 2016
Again, this whole thing is not clear. I filed a feature request to the Google GeoCode team asking for a clarification update to the documentation to address the use of Browser API keys for geocode lookups.
The documentation for the Geocoding Web Service states:
Standard API users: If you're using the API under the standard plan, you must use a server key (a type of API key) set up in a project of your choice.
The error message indicates you are using a browser key.

Bogus "This web site needs a different Google Maps API key" with STATIC image map api

Starting from recently, any request I try to get a static image from the Google Static Map API gets this text response:
This web site needs a different Google Maps API key
According to documentation https://developers.google.com/maps/documentation/staticmaps/#Limits
Note that the use of a key is not required, though it is recommended. Examples in this document do not include the key parameter so that they will work for all users who cut-and-paste the code.
Has this changed and did they forget to document it? There's a warning at the doc page that says the usage limits have changed (though then the usage limit that are claimed are the same as before!!) but it doesn't say that the use of an API key has become required.
If I had hit the usage limit, which I certainly haven't, then I would (or should) get a different response, as I experienced in the past.
The exact same requests used to work until recently.
Can anybody clarify?
Example request:
http://maps.google.com/staticmap?center=45.54309129999999,-73.62077841957398&zoom=16&size=480x360&maptype=mobile&markers=45.54309129999999,-73.62077841957398&sensor=false
I appears you are using an old URL for V1 (whose deprecation period has ended), for V2 it has to be:
https://maps.googleapis.com/maps/api/staticmap?center=45.54309129999999,-73.62077841957398&zoom=16&size=480x360&maptype=hybrid&markers=45.54309129999999,-73.62077841957398&sensor=false&mobile=true

What steps should I take to protect my Google Maps API Key?

I have obtained a Google Maps API key for my domain.
The examples provided when I obtained my key show the key embedded in request parameters, for example:
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=my-key" type="text/javascript"></script>
I appreciate that the referrer field in requests must match my domain, is it safe to make my key visible in script tags and the like? Or are there any other steps I should take?
Considering that key has to be included in the <script> tags of your HTML pages, to load the JS files/data from google's servers, there is nothing you can do :
you must put it in your HTML files
every one can take a look at those.
Still, it doesn't really matter : if anyone tries to use this key on another domain than yours, they will get a Javascript alert -- which is not nice for ther users.
So :
There is nothing you can do ; this is the way it works
And there is not much you should worry about, I'd say.
There is setting on Google API console that can protect your API bandwith usage from being used by another domain/user. You can restrict and protect that by using referrer on the API console. API Key will reject requests without referrers that match your restrictions.
Here is screenshot from Google for API Key that can only be used by Google frowm its two domains.
Though this question is a few years old it's a very good one. As I understand it exposing API keys, even if they are domain matched, could still lead to abuse. There's a post on Security Stack Exchange here that covers this in more detail.
The steps that you can take to avoid potential abuse have been published by Google here:
Best Practice Guide for securely using APIs:
https://support.google.com/cloud/answer/6310037?hl=en
Though I would recommend taking all of it on board, there is an approach that would deal with the specific example that was posted by Brabster and that's to store the key in an environment variable. This way all you need to do is to substitute the key for a server-side variable that is stored within your project. However, be sure not to commit the file that stores the key to a public repository.
You should use back end/server side to protect and handle key. In my case I used Django f/w server side which can serve a ajax call to get the key from server script/db then pass it onto google api.