Monodroid模拟器检索位置问题
当我在模拟器中运行 Monodroid 应用程序时,我很难检索位置。我的代码如下所示:
LocationManagerlocationsManager = (LocationManager)threadSurfaceView.Context.GetSystemService(Context.LocationService);
位置 =locationsManager.GetLastKnownLocation(Android.Content.Context.LocationService);
然而,这似乎总是返回 null。我是否必须以某种方式配置模拟器,以便它具有位置服务和/或位置?
我还尝试添加一个 LocationListener:
locationListener = new MyLocationListener();
locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 120000, 0, locationListener);
但我在这里遇到的问题是创建 MyLocationListener 类。我实现了四个公共方法(OnLocationChanged(Location) 等),但 Visual Studio 抱怨缺少 Android.Runtime.IJavaObject 方法 - 有没有人有实现 ILocationListener 的类的简单示例?
感谢您的任何帮助。马丁
I am having difficulty getting my Monodroid application retrieve a location when I run it in an emulator. My code looks something like this:
LocationManager locationsManager = (LocationManager)threadSurfaceView.Context.GetSystemService(Context.LocationService);
location = locationsManager.GetLastKnownLocation(Android.Content.Context.LocationService);
However, this always seems to return null. Do I have to configure the emulator in some way so that it has a locaion service and/or location?
I also tried adding a LocationListener:
locationListener = new MyLocationListener();
locationsManager.RequestLocationUpdates(LocationManager.GpsProvider, 120000, 0, locationListener);
But the problem I had here was to create the MyLocationListener class. I implemented the four public methods (OnLocationChanged(Location) and so on), but Visual Studio complained about a missing Android.Runtime.IJavaObject method - does anyone have a simple example of a class that implements ILocationListener?
Thanks for any help. Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处获得了一个示例链接
我在https://github.com/gshackles/Sample-Projects/blob/master/MonoDroid/MonoDroidSamples/MonoDroidSamples/DemoActivities/LocationDemo/LocationActivity.cs
在我的 Nexus S 上工作正常,但仍然无法工作模拟器 - 所以(也许)问题不是代码问题。
我喜欢这个示例中获取“Activity”来实现 ILocationListener 以及 Activity 的技术——这是一个从“监听器”函数中获取数据的巧妙解决方案,当它被包装到另一个类中时,这个函数一直让我头疼。
我下载了样本包,如果您执行相同的操作,那么您将需要获取一个 mp3 文件 - 将其重命名为 volbeat.mp3 并将其添加到“资源”内的“raw”文件夹中,因为它丢失了。
I got a kindly link to a sample at
https://github.com/gshackles/Sample-Projects/blob/master/MonoDroid/MonoDroidSamples/MonoDroidSamples/DemoActivities/LocationDemo/LocationActivity.cs
Which works fine on my Nexus S but still will not work on the emulator - so (perhaps) the issue is not a code issue.
I liked the technique in this sample of getting the "Activity" to implement ILocationListener as well as Activity - a neat solution to getting data back out of the "listener" function which had been giving me headaches when it was wrapped into another class.
I downloaded the bundle of samples and if you do the same then you will need to grab an mp3 file - rename it volbeat.mp3 and add it to the "raw" folder within "Resources" as it is missing.
部分答案,因为我正在解决同样的问题。
实现 ILocationListener 的侦听器类需要像
public class myLocationListener 一样声明:Java.Lang.Object, ILOcationListener
{
//加上您确定的公共函数
我的尝试如下
所示:
但即使我使用 TelNet 推送地理修复位置,iAmHere 在模拟器上也为空
partial answer as I am working on the same problem.
Your listener class that implements ILocationListener needs to be declared like
public class myLocationListener : Java.Lang.Object, ILOcationListener
{
//plus the public functions you identified
}
My attempt looks like this:
but iAmHere is null on the emulator even when I have used TelNet to push a geo fix location through