NativeGeocoderReverseResult 在导入 ionic4 + 电容器时出错
NativeGeocoderReverseResult getting error while importing in ionic4 + capacitor
从本机导入 NativeGeocoderReverseResult 时出错 geocoder.I 我正在使用带电容器的 ionic4
从'@ionic-native/native-geocoder/ngx'导入{NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderOptions};
除了 NativeGeocoderForwardResult 之外的所有其他内容都可以正确导入
import { Component } from '@angular/core';
import { Plugins, Capacitor, CameraSource, CameraResultType, CameraDirection, Camera, Geolocation } from '@capacitor/core';
import { NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderForwardResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
selectedImage: string;
coordinates: { lat: number; long: number; };
resultValue: any;
constructor(private mediaCapture: MediaCapture, private alertcontroller: AlertController, private nativeGeocoder: NativeGeocoder) {
this.getLocation();
}
getLocation() {
if (!Capacitor.isPluginAvailable('Geolocation')) {
this.alertcontroller.create({header: 'could not fetch location'});
return;
}
Plugins.Geolocation.getCurrentPosition().then(position => {
this.coordinates = { lat: position.coords.latitude, long: position.coords.longitude};
console.log('coordinates-oojj', this.coordinates);
});
const options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5
};
this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818, options)
.then((result: NativeGeocoderReverseResult[]) => {
this.resultValue = result;
console.log('resultValue',this.resultValue)
console.log(JSON.stringify(result[0]))}
)
.catch((error: any) => console.log(error));
}
}
NativeGeocoderReverseResult 不再是 Ionic 的一部分。插件 (native-geocoder) 已更新至 3.2.0。文档已弃用。推荐使用新的导入语句:
import { NativeGeocoder, NativeGeocoderResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder/ngx';
使用以下代码:
let options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5
};
this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818, options)
.then((result: NativeGeocoderResult[]) => console.log(JSON.stringify(result[0])))
.catch((error: any) => console.log(error));
this.nativeGeocoder.forwardGeocode('Berlin', options)
.then((result: NativeGeocoderResult[]) => console.log('The coordinates are latitude=' + result[0].latitude + ' and longitude=' + result[0].longitude))
.catch((error: any) => console.log(error));
如您所见,NativeGeocoderReverseResult 和 NativeGeocoderForwardResult 都被 NativeGeocoderResult 替换了。
从本机导入 NativeGeocoderReverseResult 时出错 geocoder.I 我正在使用带电容器的 ionic4
从'@ionic-native/native-geocoder/ngx'导入{NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderOptions}; 除了 NativeGeocoderForwardResult 之外的所有其他内容都可以正确导入
import { Component } from '@angular/core';
import { Plugins, Capacitor, CameraSource, CameraResultType, CameraDirection, Camera, Geolocation } from '@capacitor/core';
import { NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderForwardResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
selectedImage: string;
coordinates: { lat: number; long: number; };
resultValue: any;
constructor(private mediaCapture: MediaCapture, private alertcontroller: AlertController, private nativeGeocoder: NativeGeocoder) {
this.getLocation();
}
getLocation() {
if (!Capacitor.isPluginAvailable('Geolocation')) {
this.alertcontroller.create({header: 'could not fetch location'});
return;
}
Plugins.Geolocation.getCurrentPosition().then(position => {
this.coordinates = { lat: position.coords.latitude, long: position.coords.longitude};
console.log('coordinates-oojj', this.coordinates);
});
const options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5
};
this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818, options)
.then((result: NativeGeocoderReverseResult[]) => {
this.resultValue = result;
console.log('resultValue',this.resultValue)
console.log(JSON.stringify(result[0]))}
)
.catch((error: any) => console.log(error));
}
}
NativeGeocoderReverseResult 不再是 Ionic 的一部分。插件 (native-geocoder) 已更新至 3.2.0。文档已弃用。推荐使用新的导入语句:
import { NativeGeocoder, NativeGeocoderResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder/ngx';
使用以下代码:
let options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5
};
this.nativeGeocoder.reverseGeocode(52.5072095, 13.1452818, options)
.then((result: NativeGeocoderResult[]) => console.log(JSON.stringify(result[0])))
.catch((error: any) => console.log(error));
this.nativeGeocoder.forwardGeocode('Berlin', options)
.then((result: NativeGeocoderResult[]) => console.log('The coordinates are latitude=' + result[0].latitude + ' and longitude=' + result[0].longitude))
.catch((error: any) => console.log(error));
如您所见,NativeGeocoderReverseResult 和 NativeGeocoderForwardResult 都被 NativeGeocoderResult 替换了。