当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Detect if street address missing

问题描述:

I am using ngAutocomplete https://github.com/wpalahnuk/ngAutocomplete to get search results of address

But is there a way to make sure the picked item has street address?

For example: 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>

It lets me pick just street name without address. I want to be able to invalidate this option.

UPDATE 1

I am thinking something like this where I can get Street Number. If it's empty, then it's invalid:

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

网友答案:

What you can do is to play around with the supported types. You need to specifiy an attribute named 'options':

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

And provide an options object in scope:

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

The above will allow you to filter "results with a precise address" within Great Britain. What "precise address" means is entirely up to the Google APIs.

网友答案:

I got it: 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);
  });
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: