【发布时间】:2021-12-09 16:50:59
【问题描述】:
我有一个关于离子的问题,我将数据存储在第一页作为来自用户的输入数据,包括位置,所以我如何在第二页上检索我的数据,这是我第一页的代码(打字稿代码)
export class HomePage {
//tags: Tag[];
locations :UserLocation[];
tag: string;
locationName: string;
recipientName: string;
phoneNumber: string;
address: string;
showTagList: boolean;
showTagButtonText: string;
constructor(public router:Router,private sanitizer:DomSanitizer, private storage: Storage,private geolocation: Geolocation, private nativeGeocoder: NativeGeocoder) {
//this.tags = [];
this.locations = [];
}
async ngOnInit()
{
await this.storage.create();
this.retrieveList();
}
async retrieveList()
{
//this.tags = await this.storage.get("tags");
this.locations = await this.storage.get("locations");
}
getMyLocation()
{
this.geolocation.getCurrentPosition().then( data => this.getLocationDetails(data));
}
getLocationDetails(location: GeolocationPosition)
{
let options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5
};
this.nativeGeocoder.reverseGeocode(location.coords.latitude, location.coords.longitude, options).then((result: NativeGeocoderResult[]) => this.handleLocation(location,result));
}
handleLocation(location: GeolocationPosition,result:NativeGeocoderResult[])
{
if(this.locations == null)
this.locations = [];
let mylocation: UserLocation = new UserLocation(this.address,this.phoneNumber,this.recipientName ,this.locationName,location,this.sanitizer,result);
this.locations.push(mylocation);
this.storage.set("locations",this.locations);
}}
【问题讨论】:
标签: android typescript ionic-framework local-storage cross-platform