javascript - Gmaps NoAPIKey 错误

标签 javascript php wordpress google-maps

我正在将两个脚本加载到我的结帐页面中:

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 ); 

...但尽管我在上面的 URL 中正确提供了 key ,但我得到以下信息:

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

最佳答案

第 1 步:请转到您的 Google Console并从概览选项卡启用 Google Maps JavaScript API,然后转到 Credentials 选项卡并为您的项目创建一个 API key 。

第 2 步:将以下行添加到您的 html 中,并将 yourKEYhere 更改为您的 api key 。

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

第 3 步:使用 gmaps.js plugin .

祝你好运!

关于javascript - Gmaps NoAPIKey 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36210069/

相关文章:

php - WordPress/WooCommerce : cronjob not firing function within class that extends WC_Email

javascript - 转到下一页 - 按钮

javascript - Angular 2 匹配/合并/推送和更新 Json

php - 重新声明功能适用于旧服务器但不适用于新服务器

PHP/SQL 问题 : Data from sql wont display

jQuery On Click 函数只工作一次

javascript - ng-repeat 在 iOS 中不起作用

javascript - 函数在第二次出现时不起作用?

php - Yii2相册图片->点赞关系

WordPress 搜索引擎优化问题