Google address autocomplete make address restriction

Viewed 40

I use google autocomplete in my angular12 project.

Here is the component where I use autocomplete:

TypeScript:

@Component({
selector: 'app-address-manager',
templateUrl: './address-manager.component.html',
styleUrls: ['./address-manager.component.scss']
})

export class AddressManagerComponent implements OnInit {

  title = 'google-places-autocomplete';
  userAddress: string = ''
  userLatitude: string = ''
  userLongitude: string = ''

  constructor() { }

  ngOnInit(): void {
  }

  handleAddressChange(address: any) {
    this.userAddress = address.formatted_address
    this.userLatitude = address.geometry.location.lat()
    this.userLongitude = address.geometry.location.lng()
  }
}

Template:

   <div class="form-row">
      <div class="form-group col-lg-12 col-md-12">
        <label for="website">Address</label>
        <input class="form-control" id="googleAddressSelection" ngx-google-places-autocomplete
          (onAddressChange)="handleAddressChange($event)" />
      </div>
    </div>

I need to make countries restrictions, I need that autocomplete will return results only from USA and Canada.

My question is how can I make restrictions that autocomplete return results only from specific countries?

0 Answers
Related