В браузере я получаю адрес в виде объекта, подобного следующему:
"sender": {
"name": "Mary Jane",
"address": "Jalan Tekronat",
"city": "LAKSI",
"state": "Bangkok",
"country": "Thailand",
"email": "",
"mobile": "1234567890",
"postalcode":"10010",
"formatedAddress":"G218 Rama I Road, Pathum Wan, Bangkok, Thailand",
"countryShortName":"TH",
"countrySearchShortName":"TH"
},
Поскольку у меня есть адрес, клиент просит предварительно заполнить детали в компоненте автозаполнения.как это сделать?Я не могу найти способ сделать это.
вот мой компонент:
this.sender = new google.maps.places.Autocomplete(this.searchSenderAddressRef.nativeElement, {
types:["address"]
});
google.maps.event.addListener(this.senderAddressAutoComplete, 'place_changed', function(value){
var place = that.senderAddressAutoComplete.getPlace();
var address = '';
if (place.address_components) {
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ');
let getPostalCode = place.address_components.find( obj => obj.types.includes("postal_code") );
let getCountry = place.address_components.find( obj => obj.types.includes("country") );
let getCity = place.address_components.find( obj => obj.types.includes("locality") );
let getState = place.address_components.find( obj => obj.types.includes("administrative_area_level_2") );
that.sharableData.bd.shipment.sender.postalcode = getPostalCode && (getPostalCode.long_name || "");
that.sharableData.bd.shipment.sender.address = address || "";
that.sharableData.bd.shipment.sender.country = getCountry.long_name || "";
that.sharableData.bd.shipment.sender.state = getState && (getState.long_name || "");
that.sharableData.bd.shipment.sender.city = getCity && (getCity.long_name || "");
that.sharableData.bd.shipment.sender.formatedAddress = place.formatted_address || "";
that.sharableData.bd.shipment.sender.countryShortName = getCountry && (getCountry.short_name || "");
that.senderAddress.setValue(address);
that.sharedData.updateSharedQuoteDatas(that.sharableData);
}
})
кто-нибудь мне поможет?