eozzy
eozzy

Reputation: 68710

Gmaps NoAPIKey error

I'm loading two scripts into my checkout page:

function wpb_adding_scripts() {
    if ( function_exists( 'is_woocommerce' ) ) {
        if ( is_woocommerce() && is_checkout() ) {
            wp_register_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=[iprovidemykeyhere]&callback=initMap');
            wp_register_script('location_tracker', get_stylesheet_directory_uri() . '/js/track_location.js', array('google-maps-api'));

            wp_enqueue_script('google-maps-api');
            wp_enqueue_script('location_tracker');

        }
    }
} 
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts', 999 ); 

... but I get the following although I am correctly providing the key in the URL above:

Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys

Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required

Upvotes: 2

Views: 1116

Answers (1)

Saleh Mosleh
Saleh Mosleh

Reputation: 544

Step 1: please go to your Google Console and enable Google Maps JavaScript API from overview tab, so go to Credentials tab and make an API key for your project.

Step 2: add below line to your html and change yourKEYhere by your api key.

<script src="https://maps.googleapis.com/maps/api/js?key=yourKEYhere"></script>

Step 3: use gmaps.js plugin.

Good luck!

Upvotes: 5

Related Questions