I'm having trouble getting any sort of interactivity from my first Cordova project. I have experience in HTML, Javascript and CSS, so I figured Cordova would be a perfect introduction to hybrid app development but I can't seem to get even a basic HTML button to work on the app.
I'm using Windows 10 with Android Studio and Cordova installed. I think I've set up the project file structure correctly. I've been following Cordova's docs and have installed the geolocation plugin on all device types. For testing I'm using both the virtual android devices in Android Studio, and an android phone (OnePlus X), it's connected correctly (the app opens up on the phone whenever I type "cordova run android" into the console).
I started off trying to get my current location, and then displaying the coordinates as an alert. This wasn't working, so to try something more simple I added a button that should show an alert pop-up when clicked, but neither are working. This is my current code:
Is there something basic I'm missing? I thought I would be able to code in HTML/Javascript/CSS as normal, but would need to learn some lines of code to integrate the plugins that use native device features (like the geolocation or camera). I've made sure to install the geolocation plugin (using cordova plugin add cordova-plugin-geolocation), but the alert isn't appearing. Do I need a separate plugin to display alerts/interact with the screen?
Which is Mountain View, CA, about 8,000 miles away from me ¯_(ツ)_/¯
山景城,CA,大约8000英里远离我¯_(ツ)_ /¯吗
Here's a screenshot:
这里有一个截图:
I am testing this locally, does that make a difference? I'd really appreciate any help or advice on this, I'm probably missing something really obvious. Thank you in advance!
The onSuccess function is supposed to run after the device is ready. When it runs it should show an alert containing location details, but since I was getting the "device ready" message with no alert appearing, I decided to add a button to manually call the function as well.
I'm now certain onSuccess is not running correctly when the device is ready, because whenever I click the button to make it run manually the following error shows up in the console:
当设备准备好时,我现在肯定不能正常运行,因为每当我点击按钮使它手动运行时,就会出现以下错误:
Uncaught TypeError: Cannot read property 'coords' of undefined
未被捕获的TypeError:不能读取未定义的属性“coords”。
I'm confused as I'm using the same code as shown here: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/index.html
Also, I've noticed that the index template I'm working off contains , however when I look at the folder containing my index file, there is no cordova.js file, it's not located there, and I can't seem to find it among the cordova download, is this normal or does it need to be downloaded separately?