Phonegap GPS 插件不工作
Phonegap GPS plugin not working
我在 html 5 的应用程序中使用了 gps,而不是它看起来的实际 phonegap 插件。
我在 iPhone 上收到了一些奇怪的弹出窗口。我调查了这个问题并从 phonegap google 组得到了一些帮助:
https://groups.google.com/forum/#!topic/phonegap/YKU-QdiDk5A
基本上我的 config.xml 有两次 geo 插件,但我使用了错误的版本,而且我没有准备好在设备上使用。现在我已经解决了所有这些问题(或者我是这么认为的),现在我根本无法在 Android.
中使用 GPS
我的 config.xml 看起来像这样:
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.beerportfolio.beerportfoliopro" version="5.2.5">
<preference name="phonegap-version" value="cli-5.2.0" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />
<name>Beer Portfolio</name>
<description>Know Your Beer</description>
<author href="https://www.beerportfolio.glass" email="mike@beerportfolio.glass">Mike</author>
<content src="index.html" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="false" />
<preference name="webviewbounce" value="false" />
<preference name="disallowOverscroll" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="black-opaque" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="disable-cursor" value="false" />
<preference name="android-minSdkVersion" value="10" />
<preference name="android-targetSdkVersion" value="19" />
<preference name="android-installLocation" value="auto" />
<gap:plugin name="org.apache.cordova.battery-status" source="npm" />
<gap:plugin name="org.apache.cordova.camera" source="npm"/>
<gap:plugin name="org.apache.cordova.media-capture" source="npm"/>
<gap:plugin name="org.apache.cordova.console" source="npm" />
<gap:plugin name="org.apache.cordova.contacts" source="npm"/>
<gap:plugin name="org.apache.cordova.device" source="npm" />
<gap:plugin name="org.apache.cordova.device-motion" source="npm"/>
<gap:plugin name="org.apache.cordova.device-orientation" source="npm"/>
<gap:plugin name="org.apache.cordova.dialogs" source="npm"/>
<gap:plugin name="org.apache.cordova.file" source="npm"/>
<gap:plugin name="org.apache.cordova.file-transfer" source="npm"/>
<gap:plugin name="org.apache.cordova.globalization" source="npm"/>
<gap:plugin name="org.apache.cordova.inappbrowser" source="npm"/>
<gap:plugin name="org.apache.cordova.media" source="npm"/>
<gap:plugin name="org.apache.cordova.network-information" source="npm"/>
<gap:plugin name="org.apache.cordova.splashscreen" source="npm"/>
<gap:plugin name="org.apache.cordova.vibration" source="npm"/>
<icon src="icon.png" />
<gap:splash src="splash.png" gap:platform="android" gap:qualifier="port-ldpi" />
<gap:splash src="splash.png" gap:platform="android" gap:qualifier="port-mdpi" />
<gap:splash src="splash.png" gap:platform="android" gap:qualifier="port-hdpi" />
<gap:splash src="splash.png" gap:platform="android" gap:qualifier="port-xhdpi" />
<gap:splash src="splash.png" gap:platform="blackberry" />
<gap:splash src="splash.png" gap:platform="ios" width="320" height="480" />
<gap:splash src="splash.png" gap:platform="ios" width="640" height="960" />
<gap:splash src="splash.png" gap:platform="ios" width="640" height="1136" />
<gap:splash src="splash.png" gap:platform="ios" width="768" height="1024" />
<gap:splash src="splash.png" gap:platform="ios" width="1024" height="768" />
<gap:splash src="splash.png" gap:platform="winphone" />
<access origin="*" />
<gap:plugin name="com.phonegap.plugins.barcodescanner" source="npm" />
<gap:plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" source="npm" />
<!-- iPhone / iPod Touch - lower 4s -->
<icon src="icon-57.png" gap:platform="ios" width="57" height="57" />
<icon src="icon.png" gap:platform="ios" width="114" height="114" />
<icon src="icon-72.png" gap:platform="ios" width="72" height="72" />
<!-- iPhone / iPod Touch - 5-5s -->
<icon src="icon.png" gap:platform="ios" width="60" height="60" />
<icon src="icon.png" gap:platform="ios" width="120" height="120" />
<!-- iPhone6-6+ -->
<icon src="icon.png" gap:platform="ios" width="180" height="180" />
<!-- Settings Icon -->
<icon src="icon.png" gap:platform="ios" width="29" height="29" />
<icon src="icon.png" gap:platform="ios" width="58" height="58" />
<!-- Spotlight Icon -->
<icon src="icon.png" gap:platform="ios" width="40" height="40" />
<icon src="icon.png" gap:platform="ios" width="80" height="80" />
<plugin name="cordova-plugin-whitelist" version="1" source="npm"/>
<gap:plugin name="org.apache.cordova.device" version="0.2.3" source="npm"/>
<gap:plugin name="cordova-plugin-geolocation" source="npm"/>
<feature name="http://api.phonegap.com/1.0/battery" />
<feature name="http://api.phonegap.com/1.0/camera" />
<feature name="http://api.phonegap.com/1.0/network" />
<feature name="http://api.phonegap.com/1.0/notification" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
我的页面有 javascript,我想使用 GPS 插件开头:
$(document).on('deviceready', function () {
然后我尝试通过以下方式获取 GPS 坐标:
navigator.geolocation.getCurrentPosition(showPosition);
function showPosition(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
当我在 phone 上加载应用程序时,页面上似乎没有执行任何操作。我也尝试使用此组合启动页面以准备好在设备上使用,但它也没有用:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("navigator.geolocation works well");
}
任何关于为什么我的 GPS 不工作的 idas?
我需要 HTML 中的一行代码来解决这个问题。我忘了补充:
<script src='phonegap.js'></script>
我在 html 5 的应用程序中使用了 gps,而不是它看起来的实际 phonegap 插件。
我在 iPhone 上收到了一些奇怪的弹出窗口。我调查了这个问题并从 phonegap google 组得到了一些帮助:
https://groups.google.com/forum/#!topic/phonegap/YKU-QdiDk5A
基本上我的 config.xml 有两次 geo 插件,但我使用了错误的版本,而且我没有准备好在设备上使用。现在我已经解决了所有这些问题(或者我是这么认为的),现在我根本无法在 Android.
中使用 GPS我的 config.xml 看起来像这样:
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.beerportfolio.beerportfoliopro" version="5.2.5">
<preference name="phonegap-version" value="cli-5.2.0" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />
<name>Beer Portfolio</name>
<description>Know Your Beer</description>
<author href="https://www.beerportfolio.glass" email="mike@beerportfolio.glass">Mike</author>
<content src="index.html" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="false" />
<preference name="webviewbounce" value="false" />
<preference name="disallowOverscroll" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="black-opaque" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="disable-cursor" value="false" />
<preference name="android-minSdkVersion" value="10" />
<preference name="android-targetSdkVersion" value="19" />
<preference name="android-installLocation" value="auto" />
<gap:plugin name="org.apache.cordova.battery-status" source="npm" />
<gap:plugin name="org.apache.cordova.camera" source="npm"/>
<gap:plugin name="org.apache.cordova.media-capture" source="npm"/>
<gap:plugin name="org.apache.cordova.console" source="npm" />
<gap:plugin name="org.apache.cordova.contacts" source="npm"/>
<gap:plugin name="org.apache.cordova.device" source="npm" />
<gap:plugin name="org.apache.cordova.device-motion" source="npm"/>
<gap:plugin name="org.apache.cordova.device-orientation" source="npm"/>
<gap:plugin name="org.apache.cordova.dialogs" source="npm"/>
<gap:plugin name="org.apache.cordova.file" source="npm"/>
<gap:plugin name="org.apache.cordova.file-transfer" source="npm"/>
<gap:plugin name="org.apache.cordova.globalization" source="npm"/>
<gap:plugin name="org.apache.cordova.inappbrowser" source="npm"/>
<gap:plugin name="org.apache.cordova.media" source="npm"/>
<gap:plugin name="org.apache.cordova.network-information" source="npm"/>
<gap:plugin name="org.apache.cordova.splashscreen" source="npm"/>
<gap:plugin name="org.apache.cordova.vibration" source="npm"/>
<icon src="icon.png" />
<gap:splash src="splash.png" gap:platform="android" gap:qualifier="port-ldpi" />
<gap:splash src="splash.png" gap:platform="android" gap:qualifier="port-mdpi" />
<gap:splash src="splash.png" gap:platform="android" gap:qualifier="port-hdpi" />
<gap:splash src="splash.png" gap:platform="android" gap:qualifier="port-xhdpi" />
<gap:splash src="splash.png" gap:platform="blackberry" />
<gap:splash src="splash.png" gap:platform="ios" width="320" height="480" />
<gap:splash src="splash.png" gap:platform="ios" width="640" height="960" />
<gap:splash src="splash.png" gap:platform="ios" width="640" height="1136" />
<gap:splash src="splash.png" gap:platform="ios" width="768" height="1024" />
<gap:splash src="splash.png" gap:platform="ios" width="1024" height="768" />
<gap:splash src="splash.png" gap:platform="winphone" />
<access origin="*" />
<gap:plugin name="com.phonegap.plugins.barcodescanner" source="npm" />
<gap:plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" source="npm" />
<!-- iPhone / iPod Touch - lower 4s -->
<icon src="icon-57.png" gap:platform="ios" width="57" height="57" />
<icon src="icon.png" gap:platform="ios" width="114" height="114" />
<icon src="icon-72.png" gap:platform="ios" width="72" height="72" />
<!-- iPhone / iPod Touch - 5-5s -->
<icon src="icon.png" gap:platform="ios" width="60" height="60" />
<icon src="icon.png" gap:platform="ios" width="120" height="120" />
<!-- iPhone6-6+ -->
<icon src="icon.png" gap:platform="ios" width="180" height="180" />
<!-- Settings Icon -->
<icon src="icon.png" gap:platform="ios" width="29" height="29" />
<icon src="icon.png" gap:platform="ios" width="58" height="58" />
<!-- Spotlight Icon -->
<icon src="icon.png" gap:platform="ios" width="40" height="40" />
<icon src="icon.png" gap:platform="ios" width="80" height="80" />
<plugin name="cordova-plugin-whitelist" version="1" source="npm"/>
<gap:plugin name="org.apache.cordova.device" version="0.2.3" source="npm"/>
<gap:plugin name="cordova-plugin-geolocation" source="npm"/>
<feature name="http://api.phonegap.com/1.0/battery" />
<feature name="http://api.phonegap.com/1.0/camera" />
<feature name="http://api.phonegap.com/1.0/network" />
<feature name="http://api.phonegap.com/1.0/notification" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
我的页面有 javascript,我想使用 GPS 插件开头:
$(document).on('deviceready', function () {
然后我尝试通过以下方式获取 GPS 坐标:
navigator.geolocation.getCurrentPosition(showPosition);
function showPosition(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
当我在 phone 上加载应用程序时,页面上似乎没有执行任何操作。我也尝试使用此组合启动页面以准备好在设备上使用,但它也没有用:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("navigator.geolocation works well");
}
任何关于为什么我的 GPS 不工作的 idas?
我需要 HTML 中的一行代码来解决这个问题。我忘了补充:
<script src='phonegap.js'></script>