2016-11-21 48 views
0

我使用这个链接和它的工作,但它显示警告如果API是必须为angularjs谷歌的地方自动完成

链接:https://maps.googleapis.com/maps/api/js?libraries=places

警告:util.js中:210谷歌地图API警告:NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys

请帮忙提前.Thanks。

routerApp.directive('googleplace', function() { 
 
    return { 
 
     require: 'ngModel', 
 
     link: function(scope, element, attrs, model) { 
 
      var options = { 
 
       types: [], 
 
       componentRestrictions: {} 
 
      }; 
 
      scope.gPlace = new google.maps.places.Autocomplete(element[0], options); 
 
      
 
      google.maps.event.addListener(scope.gPlace, 'place_changed', function(e) { 
 
       scope.$apply(function() { 
 
        model.$setViewValue(element.val()); 
 
        // 
 
        scope.secondplacebox = scope.chosenPlace; 
 
        var latitude = scope.gPlace.getPlace().geometry.location.lat().toFixed(6); 
 
\t    var longitude = scope.gPlace.getPlace().geometry.location.lng().toFixed(6); 
 
\t    //alert(latitude); 
 
\t \t  scope.Fn_SearchFood(latitude,longitude,scope.date); \t \t 
 
\t \t \t \t \t }); 
 
      }); 
 
     } 
 
    }; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>

回答

0

如果你想使用谷歌API你需要设置你的API密钥。您需要创建一个API密钥并将该密钥放置到脚本中。使用GoogleApi

Google Developer API

<script src="http://maps.google.com/maps/api/js?sensor=false&key=myKey"></script> 
+0

当我放置我的API时,我得到了错误---- js?libraries = places&sensor = false&key = AIzaSyDb_sP -jlvEvKsS6_7QTBwgXt0I4qCv1JY:34 Google Maps API错误:RefererNotAllowedMapError https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error 您的网站需要授权的网址: –

0

你需要为foofle开发者控制台创建一个帐户,您需要提及在其中将使用谷歌API的网站的网址。

创建帐户后,你会得到一个令牌密钥将被放置在谷歌API的脚本。

相关问题