1

在配置我定義:谷歌地圖API密鑰失效

.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 
+0

如果您將版本'2.3.3'替換爲'3.20',它應該工作 – Dario

+0

繼續不工作。以下是錯誤: js?v = 3.exp&callback = initGoogleMaps:37 Google Maps API錯誤:MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error_ .hb @ 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 –

回答

0

Error Messages描述,MissingKeyMapError是顯影劑錯誤代碼,這意味着:

The script element that loads the API is missing the required authentication parameter. If you are using the standard Maps JavaScript API, you must use a key parameter with a valid API key. If you are a Premium Plan customer, you must use either a client parameter with your client ID or a key parameter with a valid API key.

而作爲建議,見指南API keys and client IDs

如果在檢查文檔中提供的API密鑰並且問題仍然存在,請嘗試在gmaps-api-issues中的Issue 9975中給出的解決方法。遇到的問題也可能與提出的問題有關。

除此之外,最近在Geo Developers Blog上發佈的關於Building for Scale: Updates to Google Maps APIs Standard Plan的消息也可能有所幫助。