Как использовать cordova-plugin-amap в Capacitor & React. js?
Вот моя попытка
1. установить плагин npm install cordova-plugin-amap
D:\zhaopin_app_v2>npm install cordova-plugin-amap
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\jest-haste-map\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted
{"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.0.7 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted
{"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ cordova-plugin-amap@2.0.1
added 1 package from 1 contributor and audited 908791 packages in 22.929s
found 3 vulnerabilities (1 low, 2 moderate)
run `npm audit fix` to fix them, or `npm audit` for details
2. syn c npx cap sync
D:\zhaopin_app_v2>npx cap sync
√ Copying web assets from build to android\app\src\main\assets\public in 16.97ms
√ Copying native bridge in 1.93ms
√ Copying capacitor.config.json in 2.38ms
Found 3 Cordova plugins for android
cordova-plugin-amap (2.0.1)
cordova-plugin-screen-orientation (3.0.2)
es6-promise-plugin (4.2.2)
√ copy in 216.02ms
√ Updating Android plugins in 36.80ms
Found 0 Capacitor plugins for android:
Found 3 Cordova plugins for android
cordova-plugin-amap (2.0.1)
cordova-plugin-screen-orientation (3.0.2)
es6-promise-plugin (4.2.2)
√ update android in 287.93ms
√ Copying web assets from build to ios\App\public in 10.78ms
√ Copying native bridge in 2.11ms
√ Copying capacitor.config.json in 3.40ms
Found 3 Cordova plugins for ios
cordova-plugin-amap (2.0.1)
cordova-plugin-screen-orientation (3.0.2)
es6-promise-plugin (4.2.2)
√ copy in 200.36ms
√ Updating iOS plugins in 21.15ms
Found 0 Capacitor plugins for ios:
Found 3 Cordova plugins for ios
cordova-plugin-amap (2.0.1)
cordova-plugin-screen-orientation (3.0.2)
es6-promise-plugin (4.2.2)
√ copy in 586.70μp
√ update web in 7.60μp
Sync finished in 1.819s
3. запись кода
import React, { memo } from 'react';
import { IonPage } from '@ionic/react';
declare var AMapPlugin: any;
const PositionDetailPage: React.FC = () => {
if (typeof AMapPlugin != 'undefined') {
AMapPlugin.getCurrentPosition(function (data: any) {
// success
console.log(data);
}, function (err: any) {
// fail
console.log(err);
})
}
return (
<IonPage>
</IonPage>
);
};
export default memo(PositionDetailPage);
AMapPlugin до сих пор всегда не определен, Как использовать cordova-plugin-amap в Capacitor & React. js?
Большое спасибо за помощь!