如何使用angular-google-maps进行地理编码

cfl*_*cfl 1 javascript google-maps google-maps-api-3 angularjs angular-google-maps

我一直在努力研究如何使用角度模块angular-google-maps使用googles地理定位服务.使用这个模块使它很奇怪,不能像普通谷歌地图javascript v3一样进行地理定位.

例如:

var geocoder = new google.maps.Geocoder();
Run Code Online (Sandbox Code Playgroud)

谷歌未定义..

这是我到目前为止所做的:

我的angular.module:

 ...'uiGmapgoogle-maps'])

 .config(['uiGmapGoogleMapApiProvider', function (GoogleMapApi) {
                GoogleMapApi.configure({
                  key: 'X',
                  v: '3.20',
                  libraries: 'weather,geometry,visualization' 
                });
              }]);
Run Code Online (Sandbox Code Playgroud)

我的角度控制器:

.controller(...., function (.., uiGmapGoogleMapApi, GoogleMapApi){

//Map setup stuff

 var geocoder = new GoogleMapApi.Geocoder();
        geocoder.geocode( { 'address': 'something'}, function(results, status) {
         if (status == GoogleMapApi.google.maps.GeocoderStatus.OK) {
           $scope.map.control.getGMap().setCenter(results[0].geometry.location);
           $scope.map.marker.latitude = results[0].geometry.location.lat();
           $scope.map.marker.longitude = results[0].geometry.location.lng();
         } else {
           alert('Geocode was not successful for the following reason: ' + status);
         }
        });
Run Code Online (Sandbox Code Playgroud)

Geocoder说未定义.非常混淆使用什么对象,uiGmapGoogleMapApi或GoogleMapApi来引用Geocoder().以及如何设置geocoder.geocode .. 请帮忙

cfl*_*cfl 6

实现我可以避免使用http请求的所有问题:

 $http.get('https://maps.googleapis.com/maps/api/geocode/json?address=' + 
              address + '&key=X')
      .then(function(coord_results){
         $scope.queryResults = coord_results.data.results;
         $scope.geodata = $scope.queryResults[0].geometry;
       }, 
       function error(_error){
          $scope.queryError = _error;
      });
Run Code Online (Sandbox Code Playgroud)

如果有人确实知道如何在没有这个问题的情况下解决上述问题,请留言.