Monodroid模拟器检索位置问题

发布于 2024-10-15 03:56:36 字数 717 浏览 3 评论 0原文

当我在模拟器中运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你对谁都笑 2024-10-22 03:56:37

处获得了一个示例链接

我在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.

梦中的蝴蝶 2024-10-22 03:56:37

部分答案,因为我正在解决同样的问题。

实现 ILocationListener 的侦听器类需要像

public class myLocationListener 一样声明:Java.Lang.Object, ILOcationListener
{
//加上您确定的公共函数
我的尝试如下

所示:

Android.Locations.Location iAmHere;
LocationManager myLoc = (LocationManager)GetSystemservice(Context.LocationService);
iAmHere = myLoc.GetLastKnownLocation(Android.Content.Context.LocationService);

但即使我使用 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:

Android.Locations.Location iAmHere;
LocationManager myLoc = (LocationManager)GetSystemservice(Context.LocationService);
iAmHere = myLoc.GetLastKnownLocation(Android.Content.Context.LocationService);

but iAmHere is null on the emulator even when I have used TelNet to push a geo fix location through

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文