Android 模拟器存在地理定位问题
我已经使用 Android 和 2.2 模拟器一段时间了,刚刚开始遇到一个问题。我的地理位置未在模拟器中设置。起初我以为这是 PhoneGap 0.92 的问题,但在恢复到 .91 并打开旧项目后,情况也是如此。在 DDMS 中,我的坐标已设置并“发送”它们。我还远程登录并发出 geo fix 命令,并得到了 OK 响应。看起来一切都很好,但由于某种原因模拟器仍然没有任何线索。
我发现了一些旧帖子:设置时区。我就是这么做的。还是没有运气。我什至使用浏览器访问 html5demos.com/geo 看看它是否能找到我,但它没有。
这曾经有效,不知道从那以后发生了什么。我更新了 Java 版本 1.6.0.22。 Android SDK 是 2.2,API 8,修订版 2。
任何提示或技巧将不胜感激。我被困在这一点上。
我的 Phonegap/JS 调用:
var getLocation = function() {
var suc = function(p){
alert(p.coords.latitude + " " + p.coords.longitude);
};
var fail = function(error){
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
};
navigator.geolocation.getCurrentPosition(suc,fail);
}
“失败”不断发生。错误代码 2。最后一个位置提供程序已被禁用。
- 更新 仍然有同样的问题。我发现了一个我在夏天使用的较旧的地图应用程序,它是 2.1。所以我重新编译并在 2.1 模拟器上运行它,但这也不起作用。有趣的是,在 Eclipse 中,当我在 DDMS 中并将坐标发送到 2.1 时,我“看到”确认它已在模拟器中发送,但在 2.2 中却没有。
最大的区别是我现在在代理(新工作)后面,而以前我不是。我想我可以在家尝试...不确定这是否重要。
I have been using Android and the 2.2 emulator for a bit now and just started running into an issue. My geolocation is not being set in the Emulator. At first I thought it was an issue with PhoneGap 0.92 but after reverting to .91 and opening an older project the same holds true. In DDMS my coordinates are set and I 'send' them. I also telnet and issue the geo fix command and I get a OK response. It seems all is well but for some reason the emulator still has no clue.
I found some older posts re: setting the time zone. I did that. Still no luck. I even use the browser and go to html5demos.com/geo to see if it can find me and it does not.
This used to work, not sure what happened since then. I updated my version of Java 1.6.0.22. Android SDK is 2.2, API 8, revision 2.
Any tips or tricks would be appreciated. I am stuck at this point.
My Phonegap/JS call:
var getLocation = function() {
var suc = function(p){
alert(p.coords.latitude + " " + p.coords.longitude);
};
var fail = function(error){
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
};
navigator.geolocation.getCurrentPosition(suc,fail);
}
The 'fail' keeps happening. Error code 2. The last location provider was disabled.
--UPDATE
Still having the same issue. I found an older mapping application I used back in the summer, it was 2.1. So I recompiled and ran that on a 2.1 emulator and that is also not working. The funny thing is in eclipse when i am in DDMS and send coordinates to 2.1 I 'see' a confirmation that it has been sent in the emulator but with 2.2 I do not.
The big difference is I am behind a proxy now (new job) where before I was not. I guess I could try at home...not sure if that matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须将enableHighAccuracy放入getCurrentPosition,例如:
接下来,您必须telnet到模拟器,并确定您想要的位置(经度,纬度):
然后运行您的PhoneGap应用程序。
You have to put enableHighAccuracy into getCurrentPosition, for example:
Next, you have to telnet into the emulator, and geo fix the location(longitude, latitude) you want:
Then run your PhoneGap app.
我发现完成这项工作的唯一方法是远程登录到模拟器,并在触发我正在测试的代码后发出“地理修复经度纬度”。类似这样的东西可以模拟挪威特隆赫姆的 GPS 坐标(模拟器的端口通常是 5554,但这可能会因您的设置而异):
有关模拟的更多信息,请参阅 此处
The only way I have found to make this work is to telnet to the emulator and issue a "geo fix longitude latitude" after I have triggered the code which I am testing. Something like this emulates GPS coordinates for Trondheim, Norway (the port of the emulator is usually 5554, but this can vary with your settings):
More information about the emulation can be found here
我也有同样的问题。解决方案位于 http://docs.phonegap.com/phonegap_geolocation_geolocation.md 的末尾。 html#Geolocation(向下滚动):
“Android 怪癖
Android 2.x 模拟器不会返回地理定位结果,除非将enableHighAccuracy 选项设置为 true。
{enableHighAccuracy: true }”
因此,您必须在您的位置设置enableHighAccuracy navigator.geolocation.getCurrentPosition 和您的 navigator.geolocation.watchPosition 调用。
I had the same problem. The solution is at the end of http://docs.phonegap.com/phonegap_geolocation_geolocation.md.html#Geolocation (scroll down):
"Android Quirks
The Android 2.x simulators will not return a geolocation result unless the enableHighAccuracy option is set to true.
{ enableHighAccuracy: true }"
So you have to set enableHighAccuracy at your navigator.geolocation.getCurrentPosition and your navigator.geolocation.watchPosition calls.
请在
navigator.geolocation.getCurrentPosition(suc,fail);
中添加geolocationOptions {enableHighAccuracy: true }
它对我有用。
在 DDMS 中,我的坐标必须设置,然后您“发送”它们。
Please add
geolocationOptions { enableHighAccuracy: true }
innavigator.geolocation.getCurrentPosition(suc,fail);
It work's for me.
In DDMS my coordinates must set and you 'send' them.