【问题标题】:google map api key fail谷歌地图 api 密钥失败
【发布时间】:2016-08-12 15:53:59
【问题描述】:

在我定义的配置中:

.config(
    ['uiGmapGoogleMapApiProvider', function(GoogleMapApiProviders) {
        GoogleMapApiProviders.configure({
            v: '2.3.3',
            libraries: 'weather,geometry,visualization',
            key: 'AIzaSyCz2DCKjoWMnlrf0V23RGidagkYrwTce38'
        });
        }
    ]);

在 index.html 中我写道:

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

问题是我在这里得到错误:

$scope.location = function () {
        window.navigator.geolocation.getCurrentPosition(function (position) {
            $scope.$apply(function () {
                $scope.position = position.coords;
                var geocoder = new google.maps.Geocoder();
                geocoder.geocode({
                    'latLng': {
                        lat: $scope.position.latitude,
                        lng: $scope.position.longitude
                    }
                }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (results[0]) {
                            $scope.$apply(function () {
                                $scope.userLocation = results[0].formatted_address;
                            });
                        } else {
                            $scope.$apply(function () {
                                $scope.userLocation = "No se ha podido conseguir la dirección";
                            });
                        }
                    }
                });
            });
        }, function (error) {
            alert(error);
        });
    };

因为谷歌告诉我,我没有插入密钥,正如你所见,我之前这样做过

错误是:

js?v=3.exp&callback=initGoogleMaps:37 Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error_.hb @ js?v=3.exp&callback=initGoogleMaps:37(anonymous function) @ common.js:51(anonymous function) @ common.js:191c @ common.js:45(anonymous function) @ AuthenticationService.Authenticate?1shttp%3A%2F%2F47.62.226.23%3A9000%2Fangular%2Findex.html%23%2Fs…:1

【问题讨论】:

  • 如果您将版本 '2.3.3' 替换为 '3.20' 它应该可以工作
  • 继续不工作。这是错误:js?v=3.exp&callback=initGoogleMaps:37 Google Maps API 错误:MissingKeyMapError developers.google.com/maps/documentation/javascript/…@js?v=3.exp&callback=initGoogleMaps:37(匿名函数)@common.js:51(匿名函数)@common.js:191c@common.js:45(匿名函数)@AuthenticationService.Authenticate?1shttp%3A%2F%2F47.62.226.23%3A9000%2Fangular%2Findex.html%23%2Fs…:1跨度>

标签: angularjs google-maps google-maps-api-3 google-maps-api-2 api-key


【解决方案1】:

如Error Messages 中所述,MissingKeyMapError 是开发人员错误代码,这意味着:

加载 API 的脚本元素缺少必需的身份验证参数。如果您使用的是标准 Maps JavaScript API,则必须使用带有有效 API 密钥的密钥参数。如果您是高级计划客户,则必须使用带有您的客户端 ID 的客户端参数或带有有效 API 密钥的密钥参数。

按照建议,请参阅API keys and client IDs 的指南。

如果在检查文档中给出的 API 密钥后问题仍然存在,请尝试 gmaps-api-issues 中Issue 9975 中给出的解决方法。遇到的问题也可能与提出的问题有关。

除此之外,最近在 Geo 开发者博客中关于 Building for Scale: Updates to Google Maps APIs Standard Plan 的公告也可能有所帮助。

【讨论】:

    猜你喜欢
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多