Cordova Phonegap - Android地理定位显示错误:应用程序没有足够的地理定位权限错误

vktxenjb  于 2023-10-24  发布在  Android
关注(0)|答案(2)|浏览(178)

在浏览器和iOS平台的位置工作良好,并显示所需的数据.在Android上,它显示当前错误:
应用程序没有足够的地理位置权限错误

resources/Config.xml:

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  3. <preference name="AllowInlineMediaPlayback" value="false" />
  4. <preference name="BackupWebStorage" value="cloud" />
  5. <!-- Set DisallowOverscroll to true to avoid bounce effect -->
  6. <preference name="DisallowOverscroll" value="true" />
  7. <preference name="EnableViewportScale" value="false" />
  8. <preference name="KeyboardDisplayRequiresUserAction" value="true" />
  9. <preference name="MediaPlaybackRequiresUserAction" value="false" />
  10. <preference name="SuppressesIncrementalRendering" value="false" />
  11. <preference name="GapBetweenPages" value="0" />
  12. <preference name="PageLength" value="0" />
  13. <preference name="PaginationBreakingMode" value="page" />
  14. <preference name="PaginationMode" value="unpaginated" />
  15. <feature name="LocalStorage">
  16. <param name="ios-package" value="CDVLocalStorage" />
  17. </feature>
  18. <feature name="HandleOpenUrl">
  19. <param name="ios-package" value="CDVHandleOpenURL" />
  20. <param name="onload" value="true" />
  21. </feature>
  22. <feature name="IntentAndNavigationFilter">
  23. <param name="ios-package" value="CDVIntentAndNavigationFilter" />
  24. <param name="onload" value="true" />
  25. </feature>
  26. <feature name="GestureHandler">
  27. <param name="ios-package" value="CDVGestureHandler" />
  28. <param name="onload" value="true" />
  29. </feature>
  30. <feature name="PushNotification">
  31. <param name="ios-package" value="PushPlugin" />
  32. </feature>
  33. <feature name="Vibration">
  34. <param name="ios-package" value="CDVVibration" />
  35. </feature>
  36. <feature name="Device">
  37. <param name="ios-package" value="CDVDevice" />
  38. </feature>
  39. <feature name="Accelerometer">
  40. <param name="ios-package" value="CDVAccelerometer" />
  41. </feature>
  42. <feature name="Compass">
  43. <param name="ios-package" value="CDVCompass" />
  44. </feature>
  45. <feature name="Contacts">
  46. <param name="ios-package" value="CDVContacts" />
  47. </feature>
  48. <feature name="Camera">
  49. <param name="ios-package" value="CDVCamera" />
  50. </feature>
  51. <preference name="CameraUsesGeolocation" value="false" />
  52. <preference name="AndroidPersistentFileLocation" value="Internal" />
  53. <feature name="File">
  54. <param name="ios-package" value="CDVFile" />
  55. <param name="onload" value="true" />
  56. </feature>
  57. <feature name="Geolocation">
  58. <param name="ios-package" value="CDVLocation" />
  59. </feature>
  60. <feature name="Globalization">
  61. <param name="ios-package" value="CDVGlobalization" />
  62. </feature>
  63. <feature name="InAppBrowser">
  64. <param name="ios-package" value="CDVInAppBrowser" />
  65. </feature>
  66. <feature name="Capture">
  67. <param name="ios-package" value="CDVCapture" />
  68. </feature>
  69. <feature name="NetworkStatus">
  70. <param name="ios-package" value="CDVConnection" />
  71. </feature>
  72. <feature name="SplashScreen">
  73. <param name="ios-package" value="CDVSplashScreen" />
  74. </feature>
  75. <feature name="StatusBar">
  76. <param name="ios-package" value="CDVStatusBar" />
  77. <param name="onload" value="true" />
  78. </feature>
  79. <preference name="StatusBarOverlaysWebView" value="true" />
  80. <preference name="StatusBarStyle" value="default" />
  81. <feature name="Console">
  82. <param name="ios-package" value="CDVLogger" />
  83. </feature>
  84. <feature name="FileTransfer">
  85. <param name="ios-package" value="CDVFileTransfer" />
  86. </feature>
  87. <feature name="CDVWKWebViewEngine">
  88. <param name="ios-package" value="CDVWKWebViewEngine" />
  89. </feature>
  90. <feature name="http://api.phonegap.com/1.0/geolocation"/>
  91. <plugin name="cordova-plugin-geolocation" source="npm" />
  92. <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
  93. <allow-intent href="itms:*" />
  94. <allow-intent href="itms-apps:*" />
  95. <name>HelloCordova</name>
  96. <description>
  97. A sample Apache Cordova application that responds to the deviceready event.
  98. </description>
  99. <author email="[email protected]" href="http://cordova.io">
  100. Apache Cordova Team
  101. </author>
  102. <content src="index.html" />
  103. <access origin="*" />
  104. <allow-navigation href="http://*.websitename.com" />
  105. <allow-navigation href="https://*.youtube.com" />
  106. <allow-intent href="http://*/*" />
  107. <allow-intent href="https://*/*" />
  108. <allow-intent href="tel:*" />
  109. <allow-intent href="sms:*" />
  110. <allow-intent href="mailto:*" />
  111. <allow-intent href="geo:*" />
  112. </widget>

Android/res/xml/config.xml

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  3. <preference name="AllowInlineMediaPlayback" value="false" />
  4. <preference name="BackupWebStorage" value="cloud" />
  5. <!-- Set DisallowOverscroll to true to avoid bounce effect -->
  6. <preference name="DisallowOverscroll" value="true" />
  7. <preference name="EnableViewportScale" value="false" />
  8. <preference name="KeyboardDisplayRequiresUserAction" value="true" />
  9. <preference name="MediaPlaybackRequiresUserAction" value="false" />
  10. <preference name="SuppressesIncrementalRendering" value="false" />
  11. <preference name="GapBetweenPages" value="0" />
  12. <preference name="PageLength" value="0" />
  13. <preference name="PaginationBreakingMode" value="page" />
  14. <preference name="PaginationMode" value="unpaginated" />
  15. <feature name="LocalStorage">
  16. <param name="ios-package" value="CDVLocalStorage" />
  17. </feature>
  18. <feature name="HandleOpenUrl">
  19. <param name="ios-package" value="CDVHandleOpenURL" />
  20. <param name="onload" value="true" />
  21. </feature>
  22. <feature name="IntentAndNavigationFilter">
  23. <param name="ios-package" value="CDVIntentAndNavigationFilter" />
  24. <param name="onload" value="true" />
  25. </feature>
  26. <feature name="GestureHandler">
  27. <param name="ios-package" value="CDVGestureHandler" />
  28. <param name="onload" value="true" />
  29. </feature>
  30. <feature name="PushNotification">
  31. <param name="ios-package" value="PushPlugin" />
  32. </feature>
  33. <feature name="Vibration">
  34. <param name="ios-package" value="CDVVibration" />
  35. </feature>
  36. <feature name="Device">
  37. <param name="ios-package" value="CDVDevice" />
  38. </feature>
  39. <feature name="Accelerometer">
  40. <param name="ios-package" value="CDVAccelerometer" />
  41. </feature>
  42. <feature name="Compass">
  43. <param name="ios-package" value="CDVCompass" />
  44. </feature>
  45. <feature name="Contacts">
  46. <param name="ios-package" value="CDVContacts" />
  47. </feature>
  48. <feature name="Camera">
  49. <param name="ios-package" value="CDVCamera" />
  50. </feature>
  51. <preference name="CameraUsesGeolocation" value="false" />
  52. <preference name="AndroidPersistentFileLocation" value="Internal" />
  53. <feature name="File">
  54. <param name="ios-package" value="CDVFile" />
  55. <param name="onload" value="true" />
  56. </feature>
  57. <feature name="Geolocation">
  58. <param name="ios-package" value="CDVLocation" />
  59. </feature>
  60. <feature name="Globalization">
  61. <param name="ios-package" value="CDVGlobalization" />
  62. </feature>
  63. <feature name="InAppBrowser">
  64. <param name="ios-package" value="CDVInAppBrowser" />
  65. </feature>
  66. <feature name="Capture">
  67. <param name="ios-package" value="CDVCapture" />
  68. </feature>
  69. <feature name="NetworkStatus">
  70. <param name="ios-package" value="CDVConnection" />
  71. </feature>
  72. <feature name="SplashScreen">
  73. <param name="ios-package" value="CDVSplashScreen" />
  74. </feature>
  75. <feature name="StatusBar">
  76. <param name="ios-package" value="CDVStatusBar" />
  77. <param name="onload" value="true" />
  78. </feature>
  79. <preference name="StatusBarOverlaysWebView" value="true" />
  80. <preference name="StatusBarStyle" value="default" />
  81. <feature name="Console">
  82. <param name="ios-package" value="CDVLogger" />
  83. </feature>
  84. <feature name="FileTransfer">
  85. <param name="ios-package" value="CDVFileTransfer" />
  86. </feature>
  87. <feature name="CDVWKWebViewEngine">
  88. <param name="ios-package" value="CDVWKWebViewEngine" />
  89. </feature>
  90. <feature name="http://api.phonegap.com/1.0/geolocation"/>
  91. <plugin name="cordova-plugin-geolocation" source="npm" />
  92. <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
  93. <allow-intent href="itms:*" />
  94. <allow-intent href="itms-apps:*" />
  95. <name>HelloCordova</name>
  96. <description>
  97. A sample Apache Cordova application that responds to the deviceready event.
  98. </description>
  99. <author email="[email protected]" href="http://cordova.io">
  100. Apache Cordova Team
  101. </author>
  102. <content src="index.html" />
  103. <access origin="*" />
  104. <allow-navigation href="http://*.websitename.com" />
  105. <allow-navigation href="https://*.youtube.com" />
  106. <allow-intent href="http://*/*" />
  107. <allow-intent href="https://*/*" />
  108. <allow-intent href="tel:*" />
  109. <allow-intent href="sms:*" />
  110. <allow-intent href="mailto:*" />
  111. <allow-intent href="geo:*" />
  112. </widget>

AndroidManifest.xml

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.cordova.hellocordova" xmlns:android="http://schemas.android.com/apk/res/android">
  3. <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
  4. <uses-permission android:name="android.permission.INTERNET" />
  5. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  6. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  7. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  8. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  9. <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
  10. <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
  11. <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="app name" android:supportsRtl="true">
  12. <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
  13. <intent-filter android:label="@string/launcher_name">
  14. <action android:name="android.intent.action.MAIN" />
  15. <category android:name="android.intent.category.LAUNCHER" />
  16. </intent-filter>
  17. </activity>
  18. </application>
  19. <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
  20. </manifest>

插件/org.apache.cordova.geolocation/plugin.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied. See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="org.apache.cordova.geolocation" version="0.3.12">
  19. <name>Geolocation</name>
  20. <description>Cordova Geolocation Plugin</description>
  21. <license>Apache 2.0</license>
  22. <keywords>cordova,geolocation</keywords>
  23. <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git</repo>
  24. <issue>https://issues.apache.org/jira/browse/CB/component/12320638</issue>
  25. <!-- android -->
  26. <platform name="android">
  27. <config-file target="AndroidManifest.xml" parent="/*">
  28. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  29. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  30. </config-file>
  31. </platform>
  32. <!-- amazon-fireos -->
  33. <platform name="amazon-fireos">
  34. <config-file target="AndroidManifest.xml" parent="/*">
  35. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  36. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  37. </config-file>
  38. </platform>
  39. <!-- ios -->
  40. <platform name="ios">
  41. <js-module src="www/Coordinates.js" name="Coordinates">
  42. <clobbers target="Coordinates" />
  43. </js-module>
  44. <js-module src="www/PositionError.js" name="PositionError">
  45. <clobbers target="PositionError" />
  46. </js-module>
  47. <js-module src="www/Position.js" name="Position">
  48. <clobbers target="Position" />
  49. </js-module>
  50. <js-module src="www/geolocation.js" name="geolocation">
  51. <clobbers target="navigator.geolocation" />
  52. </js-module>
  53. <config-file target="config.xml" parent="/*">
  54. <feature name="Geolocation">
  55. <param name="ios-package" value="CDVLocation"/>
  56. </feature>
  57. </config-file>
  58. <header-file src="src/ios/CDVLocation.h" />
  59. <source-file src="src/ios/CDVLocation.m" />
  60. <framework src="CoreLocation.framework" />
  61. <config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
  62. <string></string>
  63. </config-file>
  64. </platform>
  65. <!-- blackberry10 -->
  66. <platform name="blackberry10">
  67. <js-module src="www/blackberry10/GeolocationProxy.js" name="GeolocationProxy">
  68. <runs />
  69. </js-module>
  70. <js-module src="www/Coordinates.js" name="Coordinates">
  71. <clobbers target="Coordinates" />
  72. </js-module>
  73. <js-module src="www/PositionError.js" name="PositionError">
  74. <clobbers target="PositionError" />
  75. </js-module>
  76. <js-module src="www/Position.js" name="Position">
  77. <clobbers target="Position" />
  78. </js-module>
  79. <js-module src="www/geolocation.js" name="geolocation">
  80. <clobbers target="navigator.geolocation" />
  81. </js-module>
  82. <config-file target="www/config.xml" parent="/widget">
  83. <feature name="Geolocation" value="Geolocation"/>
  84. </config-file>
  85. <config-file target="www/config.xml" parent="/widget/rim:permissions">
  86. <rim:permit>read_geolocation</rim:permit>
  87. </config-file>
  88. </platform>
  89. <!-- ubuntu -->
  90. <platform name="ubuntu">
  91. <js-module src="www/Coordinates.js" name="Coordinates">
  92. <clobbers target="Coordinates" />
  93. </js-module>
  94. <js-module src="www/PositionError.js" name="PositionError">
  95. <clobbers target="PositionError" />
  96. </js-module>
  97. <js-module src="www/Position.js" name="Position">
  98. <clobbers target="Position" />
  99. </js-module>
  100. <js-module src="www/geolocation.js" name="geolocation">
  101. <clobbers target="navigator.geolocation" />
  102. </js-module>
  103. <source-file src="src/ubuntu/geolocation.cpp" />
  104. <header-file src="src/ubuntu/geolocation.h" />
  105. <config-file target="config.xml" parent="/*">
  106. <feature name="Geolocation">
  107. <param policy_group="location" policy_version="1" />
  108. </feature>
  109. </config-file>
  110. </platform>
  111. <!-- wp7 -->
  112. <platform name="wp7">
  113. <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
  114. <Capability Name="ID_CAP_LOCATION" />
  115. </config-file>
  116. <source-file src="src/wp/Geolocation.cs" />
  117. </platform>
  118. <!-- wp8 -->
  119. <platform name="wp8">
  120. <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
  121. <Capability Name="ID_CAP_LOCATION" />
  122. </config-file>
  123. <source-file src="src/wp/Geolocation.cs" />
  124. </platform>
  125. <!-- windows8 -->
  126. <platform name="windows8">
  127. <config-file target="package.appxmanifest" parent="/Package/Capabilities">
  128. <DeviceCapability Name="location" />
  129. </config-file>
  130. <js-module src="src/windows/GeolocationProxy.js" name="GeolocationProxy">
  131. <runs />
  132. </js-module>
  133. <js-module src="www/Coordinates.js" name="Coordinates">
  134. <clobbers target="Coordinates" />
  135. </js-module>
  136. <js-module src="www/PositionError.js" name="PositionError">
  137. <clobbers target="PositionError" />
  138. </js-module>
  139. <js-module src="www/Position.js" name="Position">
  140. <clobbers target="Position" />
  141. </js-module>
  142. <js-module src="www/geolocation.js" name="geolocation">
  143. <clobbers target="navigator.geolocation" />
  144. </js-module>
  145. </platform>
  146. <!-- windows universal apps (Windows 8.1, Windows Phone 8.1, Windows 8.0) -->
  147. <platform name="windows">
  148. <config-file target="package.appxmanifest" parent="/Package/Capabilities">
  149. <DeviceCapability Name="location" />
  150. </config-file>
  151. <js-module src="src/windows/GeolocationProxy.js" name="GeolocationProxy">
  152. <runs />
  153. </js-module>
  154. <js-module src="www/Coordinates.js" name="Coordinates">
  155. <clobbers target="Coordinates" />
  156. </js-module>
  157. <js-module src="www/PositionError.js" name="PositionError">
  158. <clobbers target="PositionError" />
  159. </js-module>
  160. <js-module src="www/Position.js" name="Position">
  161. <clobbers target="Position" />
  162. </js-module>
  163. <js-module src="www/geolocation.js" name="geolocation">
  164. <clobbers target="navigator.geolocation" />
  165. </js-module>
  166. </platform>
  167. <!-- firefoxos -->
  168. <platform name="firefoxos">
  169. <config-file target="config.xml" parent="/*">
  170. <permission name="geolocation" description="Required for accessing user location." />
  171. </config-file>
  172. <js-module src="src/firefoxos/GeolocationProxy.js" name="GeolocationProxy">
  173. <runs />
  174. </js-module>
  175. <js-module src="www/Coordinates.js" name="Coordinates">
  176. <clobbers target="Coordinates" />
  177. </js-module>
  178. <js-module src="www/PositionError.js" name="PositionError">
  179. <clobbers target="PositionError" />
  180. </js-module>
  181. <js-module src="www/Position.js" name="Position">
  182. <clobbers target="Position" />
  183. </js-module>
  184. <js-module src="www/geolocation.js" name="geolocation">
  185. <clobbers target="navigator.geolocation" />
  186. </js-module>
  187. </platform>
  188. </plugin>

取位JavaScript:

  1. <script>
  2. window.onload = function() {
  3. document.addEventListener("deviceready", init, false);
  4. document.addEventListener("deviceready", onDeviceReady, false);
  5. }
  6. function init() {
  7. navigator.geolocation.getCurrentPosition(positionSuccess, positionError);
  8. }
  9. function onDeviceReady(){
  10. }
  11. function positionSuccess(position) {
  12. var latitude = position.coords.latitude;
  13. var longitude = position.coords.longitude;
  14. document.getElementById('lat').value = latitude;
  15. document.getElementById('lon').value = longitude;
  16. }
  17. function positionError(error) {
  18. alert(error.message);
  19. }
  20. </script>

任何建议或帮助将不胜感激。

t30tvxxf

t30tvxxf1#

如果有人需要答案,我在这里找到了:https://github.com/driftyco/ng-cordova/issues/743
我只是更新了插件,错误消失了:

  1. cordova plugin rm org.apache.cordova.geolocation
  2. cordova plugin add cordova-plugin-geolocation
dddzy1tm

dddzy1tm2#

在您的ionic项目中
最后在</widget>之前添加以下代码

  1. <plugin name="cordova-plugin-geolocation" spec="4.0.1">`
  2. <variable name="GEOLOCATION_USAGE_DESCRIPTION" value="App uses geolocation to determine where you are." />
  3. </plugin>
  4. <platform name="android">
  5. <uses-permission name="android.permission.ACCESS_COARSE_LOCATION" />
  6. <uses-permission name="android.permission.ACCESS_FINE_LOCATION" />
  7. <uses-permission name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
  8. </platform>

使用上述更改,当您的应用在全新安装后首次使用位置详细信息时,您的应用将自动调用权限对话框。

相关问题