mapsplugin / cordova-plugin-googlemaps

Google Maps plugin for Cordova
Apache License 2.0
1.66k stars 918 forks source link

API KEY provided but still getting “Keyless access to Google Maps Platform is deprecated.” error #2511

Closed lavenpillay closed 5 years ago

lavenpillay commented 5 years ago

I'm submitting a ... (check one with "x")

OS: (check one with "x")

cordova information: (run $> cordova plugin list)

com-sarriaroman-photoviewer 1.1.18 "PhotoViewer"
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-badge 0.8.7 "Badge"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-dialogs 2.0.1 "Notification"
cordova-plugin-facebook4 2.3.0 "Facebook Connect"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-firebase 2.0.5 "Google Firebase Plugin"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-googlemaps 2.4.6 "cordova-plugin-googlemaps"
cordova-plugin-ionic-keyboard 2.1.2 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.2.1 "cordova-plugin-ionic-webview"
cordova-plugin-local-notification 0.9.0-beta.2 "LocalNotification"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-sqlite-storage 2.4.0 "Cordova sqlite storage plugin"
cordova-support-google-services 1.2.1 "cordova-support-google-services"
phonegap-plugin-multidex 1.0.0 "Multidex"
phonegap-plugin-push 2.2.3 "PushPlugin"
uk.co.workingedge.phonegap.plugin.launchnavigator 4.2.1 "Launch Navigator"

If you use @ionic-native/google-maps, please tell the package.json (only @ionic-native/core and @ionic-native/google-maps are fine mostly)

@ionic-native/core : "^4.17.0"
@ionic-native/google-maps : "^4.15.1"

Current behavior: Despite providing a valid API KEY, from an account with Billing Enabled, and a newly generated API KEY, I am getting this error when attempting to use the "locate place" function:

{"error_message":"Keyless access to Google Maps Platform is deprecated. 
Please use an API key with all your API calls to avoid service interruption. 
For further details please refer to http://g.co/dev/maps-no-account",
"results":[],"status":"OVER_QUERY_LIMIT"}

Expected behavior: API Call returns a valid response (and then the application re-centers on that location). Note : This did work when last tested, a few months ago, and with a different API KEY, so the functionality itself does work.

Related code, data or error log (please format your code or data):

Plugin was added like so, with the valid API Key

ionic cordova plugin add cordova-plugin-googlemaps \
--variable API_KEY_FOR_ANDROID="MY_API_KEY" \
--variable API_KEY_FOR_IOS="MY_API_KEY"

The code making the call to the GeoCoding api :

    search() {
        console.log("--- Starting Search ---");
        var cityInQuotes = "\"" + this.searchValue + "\""
        var geocodeURL = "https://maps.googleapis.com/maps/api/geocode/json?address=" + cityInQuotes; //return JSON
        console.log(geocodeURL);
        this.http.get(geocodeURL).subscribe(
            results => { this.printCoordinates(results) },
            error => this.errorMessage = <any>error);
    }

I have also tried using curl to make the call directly - and get the same error whether I provide a "key" parameter or not :

curl https://maps.googleapis.com/maps/api/geocode/json?address=Cape&key=MY_API_KEY

{
   "error_message" : "Keyless access to Google Maps Platform is deprecated. Please use an API key with all your API calls to avoid service interruption. For further details please refer to http://g.co/dev/maps-no-account",
   "results" : [],
   "status" : "OVER_QUERY_LIMIT"
}

I have also tried various combinations of Remove/Add Plugin and Remove/Add Platform.

Please let me know if you require further information.

makers-mark commented 5 years ago

If you are getting a direct message that the "API key is invalid", you should start there. There have been changes within the Google ecosystem as far as API keys go in the past couple of months, which you obviously know (by describing the payment).

I would suggest contacting them, or reading this, which involves a different API service (javascript, but is still pertinent given the changes) and double checking your payment status.

Edit: Have you went to the link that you were given at the end of your post? http://g.co/dev/maps-no-account

lavenpillay commented 5 years ago

Thanks for the quick response ! I confirmed all the obvious things in from the Google links, but I just spotted this :

In order to switch over to the new pay as you go pricing plan, you must create a new project, as your existing Premium project cannot be transferred. You must get new API keys, and use them to to replace your existing keys.

I'm not in control of billing (client is), so maybe I just need to re-create the project ? I'll try that. Thanks again for the response.

wf9a5m75 commented 5 years ago

https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/README.md#api-key

wf9a5m75 commented 5 years ago
Keyless access to Google Maps Platform is deprecated.

This message is outputted when you use Google Maps JavaScript v3 without key. It means your HTML includes <script src="https://maps.googleapis.com/maps/api/js"></script> in anywhere.


This plugin inserts <script src="https://maps.googleapis.com/maps/api/js"></script> automatically if your app does not it. If your app already has <script src="https://maps.googleapis.com/maps/api/js"></script>, this plugin skips it. This is browser platform behavior.

If you see the message on Browser platform, but you don't include <script src="https://maps.googleapis.com/maps/api/js"></script>, you probably forget to specify API key in your code. https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/README.md#api-key


If you see the message even on Android platform, you must check your HTML files. Because this plugin does not use Google Maps JavaScript v3 in Android platform.

ghost commented 5 years ago

in index.html

<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOURKEY" type="text/javascript"></script>

in app.component.ts

 this.platform.ready().then(() => {
      Environment.setEnv({
        // api key for server
        'API_KEY_FOR_BROWSER_RELEASE': 'YOURKEY',

        // api key for local development
        'API_KEY_FOR_BROWSER_DEBUG': 'YOURKEY'
      });
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
wf9a5m75 commented 5 years ago

Remove <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOURKEY" type="text/javascript"></script>

zairecrypto commented 5 years ago

Facing the same issue.

I just got my API key (with billing), but whenever i'm trying to test an maps.googleapis.com/maps/api/distancematrix/json?origins=origin&destinations=destination?key=myApiKey, i'm getting the bellow message:

{ "error_message" : "Keyless access to Google Maps Platform is deprecated. Please use an API key with all your API calls to avoid service interruption. For further details please refer to http://g.co/dev/maps-no-account", "routes" : [], "status" : "OVER_QUERY_LIMIT" }