Vue+Capacitor v4安卓端Geolocation插件未实现错误求助
Capacitor v4 + Vue 移动端APP Geolocation插件生产环境报错问题
我们使用Vue.js和Capacitorjs v4开发移动端APP,采用Capacitor官方的@capacitor/geolocation插件获取用户位置。本地localhost测试时功能正常,但将WebView链接切换至生产环境后,出现错误:Uncaught (in promise) Error: "Geolocation" plugin is not implemented on android
尽管Android Studio日志显示该插件已成功注册:
D/EgretLoader: The context is not activity D/Capacitor: Starting BridgeActivity D/Capacitor: Registering plugin: WebView D/Capacitor: Registering plugin: AppLauncher D/Capacitor: Registering plugin: Geolocation D/Capacitor: Registering plugin: Preferences D/Capacitor: Registering plugin: PushNotifications D/Capacitor: Registering plugin: SplashScreen
核心代码
if(Capacitor.getPlatform() != "web"){ const coordinates = await Geolocation.getCurrentPosition(); finalResult = Object.assign(stringObject,{"time" : nd},{"longitude" : coordinates.coords.longitude.toString(), "latitude": coordinates.coords.latitude.toString()}); }
MainActivity.java代码
public class MainActivity extends BridgeActivity {}
已尝试的无效解决方案
- 在MainActivity.java中手动注册插件
- 在build.gradle中设置minifyEnabled false
问题已持续两周仍未解决,寻求帮助。
更新:配置文件内容
{ "appId": "com.example.is.app", "appName": "App Name", "webDir": "dist", "bundledWebRuntime": false, "plugins": { "SplashScreen": { "launchShowDuration": 4000, "launchAutoHide": true, "fadeOutDuration": 1000, "splashFullScreen": false, "splashImmersive": false }, }, "cordova": {}, "server": { "cleartext": true, "hostname": "hemera-is-dev", //"url": "https://www.myremotewebsite.com/app/dist/",(not working even though other plugins work normally on the remote website) "url": "http://localhost/app/dist/", "allowNavigation": [ "*" ] } }
内容的提问来源于stack exchange,提问作者Majd Harb
相关产品推荐
相关产品推荐

