【问题标题】:Detect if street address missing检测街道地址是否丢失
【发布时间】:2015-05-22 08:40:20
【问题描述】:

我正在使用 ngAutocomplete https://github.com/wpalahnuk/ngAutocomplete 来获取地址的搜索结果

但是有没有办法确保挑选的物品有街道地址?

例如:http://plnkr.co/edit/GE34ojss9xMGm0024FvM?p=preview

<div class="form-group move-down">
    <label for="Autocomplete">Generic Autocomplete</label>
    <input type="text" id="Autocomplete" class="form-control" ng-autocomplete ng-model="result1" />
</div>
<div>result: {{result1}}</div>

它让我只选择没有地址的街道名称。我希望能够使此选项无效。

更新 1

我正在考虑这样的事情,在那里我可以获得街道号码。如果为空,则无效:

http://ubilabs.github.io/geocomplete/examples/custom_attribute.html

【问题讨论】:

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


    【解决方案1】:

    您可以做的就是玩弄supported types。 您需要指定一个名为“选项”的属性:

     <input type="text"  ng-autocomplete ng-model="autocomplete" options="options" details="details/>
    

    并在范围内提供一个选项对象:

    $scope.options = {
      country: 'gb',
      types: 'address'
    };
    

    以上内容可让您过滤英国境内的“具有精确地址的结果”。 “精确地址”的含义完全取决于 Google API。

    【讨论】:

    • 我试过了,它不起作用。它给了我类似55th Avenue South, Seattle, WA, United States 的东西。所以必须有一种方法来获取带有“地址”字段的“原始”对象,不是吗?
    【解决方案2】:

    我知道了:http://plnkr.co/edit/fah9XvCy9Yp0Bd3i3GKE?p=preview

    var geocoder = new google.maps.Geocoder();
    
    $scope.$watch('result1', function() {
      console.log('$scope.result1:');
      console.log($scope.result1);
      geocoder.geocode({
        address: $scope.result1
      }, function(result, status) {
        console.log(result);
        console.log(status);
      });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多