我已经使用 cordova v3.4.1 构建了 android 和 ios 应用程序,在 ios 上,地理定位功能返回得非常快并且始终运行良好,但在 android 上,有时它不起作用。
奇怪的是,在我重新启动我的 android 手机后,它工作正常。在几个多小时内,地理定位在 wifi 和 3G 中都非常迅速地定位。
但几个小时后,我再次打开应用程序,地理定位无法工作。有时当我在外面时,它可以用gps卫星定位,但很慢,经常出现超时错误。
我尝试删除应用程序并重新安装它,但问题仍然存在,除非重新启动我的 android 手机。当我重新启动我的 android 手机时,地理定位功能在未来几个小时再次正常工作。
我测试了一些安卓手机,比如samsang note2,galaxy4等,他们都有同样的问题。当我重新启动它时,他们可以非常快速地定位。
这个问题困扰我好久了,有大佬帮帮我吗?
下面是我的代码:
navigator.geolocation.getCurrentPosition(function(pos){
cb(null,pos)
},function(errMsg){
navigator.geolocation.getCurrentPosition(function(pos){
cb(null,pos)
},function(errMsg){
cb(errMsg)
}, {
enableHighAccuracy: true,
timeout: 60*1000*2,
maximumAge: 1000*60*10
});
}, {
enableHighAccuracy: false,
timeout: 10*1000,
maximumAge: 1000*60*10
});
我的配置文件:
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.geolocation.GeoBroker" />
</feature>
最佳答案
我终于解决了这个问题,现在在我的安卓手机上,getCurrentPosition 函数每次都非常快速地返回位置信息,我再也不需要重启手机了!
我不确定 cordova v3.4.1 的地理定位插件是否有错误。
出现这个问题的原因是我们总是使用浏览器的navigator.geolocation.getCurrentPosition函数来定位位置,所以我们必须让应用程序使用cordova原生实现而不是html5。
这是cordova v3.4.1的解决方案,希望对你有帮助,事实上它已经解决了我的问题。
求解步骤:
1.删除 org.apache.cordova.geolocation
$ cordova plugin rm org.apache.cordova.geolocation
2.重新安装一个新的org.apache.cordova.geolocation插件
$ cordova plugin add org.apache.cordova.geolocation
3.复制插件到e:\
进入插件文件夹,例如‘YOUR_APP_FOLDER\plugins\’
将孔 org.apache.cordova.geolocation 复制到 E:\org.apache.cordova.geolocation
4.再次移除插件
$ cordova plugin rm org.apache.cordova.geolocation
5.编辑E:\org.apache.cordova.geolocation\plugin.xml中的plugin.xml
像下面这样编辑 plugin.xml 文件:
... ...
<name>Geolocation</name>
<description>Cordova Geolocation Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,geolocation</keywords>
<repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git</repo>
<issue>https://issues.apache.org/jira/browse/CB/component/12320638</issue>
<!-- android Code Comments
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permissionandroid android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
</config-file>
</platform>
-->
<!-- amazon-fireos change to android-->
<platform name="android">
<js-module src="www/Coordinates.js" name="Coordinates">
<clobbers target="Coordinates" />
</js-module>
<js-module src="www/PositionError.js" name="PositionError">
<clobbers target="PositionError" />
</js-module>
<js-module src="www/Position.js" name="Position">
<clobbers target="Position" />
</js-module>
<js-module src="www/geolocation.js" name="geolocation">
<clobbers target="navigator.geolocation" />
</js-module>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.geolocation.GeoBroker"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
</config-file>
<source-file src="src/amazon/GeoBroker.java" target-dir="src/org/apache/cordova/geolocation" />
<source-file src="src/amazon/GPSListener.java" target-dir="src/org/apache/cordova/geolocation" />
<source-file src="src/amazon/NetworkListener.java" target-dir="src/org/apache/cordova/geolocation" />
<source-file src="src/amazon/CordovaLocationListener.java" target-dir="src/org/apache/cordova/geolocation" />
</platform>
<!-- ios -->
<platform name="ios">
... ...
6.再次添加插件
$ cordova plugin add E:\org.apache.cordova.geolocation
7、运行构建commond
$ cordova build android
8.检查是否正常
检查 YOUR_APP\plugins\android.json 必须包括:
{
"xml": "<feature name=\"Geolocation\"><param name=\"android-package\" value=\"org.apache.cordova.geolocation.GeoBroker\" /></feature>",
"count": 1
},
... ...
{
"xml": "<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" />",
"count": 4
},
{
"xml": "<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" />",
"count": 4
},
{
"xml": "<uses-permission android:name=\"android.permission.ACCESS_LOCATION_EXTRA_COMMANDS\" />",
"count": 1
}
检查 YOUR_APP\platforms\android\AndroidManifest.xml 必须包括:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
检查 YOUR_APP\platforms\android\res\xml\config.xml 必须包括:
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.geolocation.GeoBroker" />
</feature>
9.运行应用
编写地理定位代码以获取纬度和经度:
navigator.geolocation.getCurrentPosition(function(pos){
alert('suc')
alert(JSON.stringify(pos))
},function(errMsg){
alert(JSON.stringify(errMsg))
navigator.geolocation.getCurrentPosition(function(pos){
alert('suc')
alert(JSON.stringify(pos))
},function(errMsg){
alert(JSON.stringify(errMsg))
}, {
enableHighAccuracy: true,
timeout: 60*1000*2,
maximumAge: 1000*60*10
});
}, {
enableHighAccuracy: false,
timeout: 60*1000,
maximumAge: 1000*60*10
});
如果您的手机支持使用 wifi/3G 定位,那么我们将立即获取位置,否则您将看到 errMsg 超时,然后 geolocation 将使用 gps 定位位置原生实现。
现在我们得到了纬度和经度,谢天谢地,再也不需要重启安卓手机了。
如果还是有问题,请尝试安装清理webview缓存的插件:
关于android - Phonegap 地理定位有时无法在 Android 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23383750/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)