【问题标题】:How to do geocoding with angular-google-maps如何使用 angular-google-maps 进行地理编码
【发布时间】:2015-12-03 20:11:09
【问题描述】:

我一直在努力研究如何将 google 的地理定位服务与 angular 模块 angular-google-maps 一起使用。使用这个模块让它变得很奇怪,并且不能以与普通谷歌地图 javascript v3 相同的方式进行地理定位。

例如:

var geocoder = new google.maps.Geocoder();

Google 未定义..

这是我目前为止的工作:

我的 angular.module:

 ...'uiGmapgoogle-maps'])

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

我的角度控制器:

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

说地理编码器未定义。 非常困惑要使用什么对象,uiGmapGoogleMapApi 或 GoogleMapApi 来引用 Geocoder()。以及应该如何设置 geocoder.geocode..? 请帮忙

【问题讨论】:

    标签: javascript angularjs google-maps google-maps-api-3 angular-google-maps


    【解决方案1】:

    意识到我可以通过使用 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;
          });
    

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

    【讨论】:

    • 我正要回答同样的问题!
    【解决方案2】:

    我在这样做时遇到了同样的问题:

      uiGmapGoogleMapApi.then(function(apiMaps) {
           var geocoder = new apiMaps.Geocoder();
           console.log(geocoder); //undefined
      });
    

    我的解决方案:

      uiGmapGoogleMapApi.then(function(apiMaps) {
           var geocoder = new google.maps.Geocoder();
           console.log(geocoder); //object
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      • 2011-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多