Determine if Google Maps API is using an invalid key during runtime

前端 未结 2 778
粉色の甜心
粉色の甜心 2020-12-22 04:12

I\'m looking for a way to determine whether a valid Google maps API key is being used. Using an invalid key, we receive an error stating that the google API has been disable

2条回答
  •  情话喂你
    2020-12-22 04:23

    Well there's something i found in Web > Maps JavaScript API > Events under title "Listening for authentication errors"

    If you want to programmatically detect an authentication failure (for example to automatically send an beacon) you can prepare a callback function. If the following global function is defined it will be called when the authentication fails.

    so you just need to define a global function:

    function gm_authFailure() { /* Code */ };
    

提交回复
热议问题