简体   繁体   English

没有位置传感器的Windows 7桌面

[英]Windows 7 Desktop without location sensor

I'm writing a windows 7 desktop C# app and I need to write code when there is a location sensor. 我正在编写Windows 7桌面C#应用程序,当有位置传感器时,我需要编写代码。 I have this: 我有这个:

            public string check(string stop)
            {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
            watcher.Start();

            watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);

            return null;

            }

        static void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
        {
            switch (e.Status)
            {
                case GeoPositionStatus.Initializing:
                    Console.WriteLine("Working on location fix");
                    break;

                case GeoPositionStatus.Ready:
                    Console.WriteLine("Have location");
                    break;

                case GeoPositionStatus.NoData:
                    Console.WriteLine("No data");
                    break;

                case GeoPositionStatus.Disabled:
                    Console.WriteLine("Disabled");
                    break;
            }
            MessageBox.Show("GO");
        }

This is really just to see if it grabs the latitude and longitude, but I don't have a sensor and I just want to know, will this work if a laptop does have a sensor? 这实际上只是为了查看它是否可以捕获纬度和经度,但是我没有传感器,我只想知道,如果笔记本电脑有传感器,这项功能是否可以工作? I can't afford to get a sensor yet so I would like to have the code and move on until I can aquire one. 我还买不起传感器,所以我想拥有代码并继续前进,直到我能买到为止。 Also, I need to stop the geocoordinatewatcher when the user logs out, so since I cant stop this in a different function, if I start another and stop that one will that stop all?These functions are called from a webapge and there are no buttons on my form. 另外,我需要在用户注销时停止geocoordinatewatcher,所以由于无法在其他功能中停止它,所以如果我启动另一个并停止该操作会停止所有操作?这些功能是从webapge调用的,没有按钮在我的表格上。 The function called when a user logs out will be stop();. 用户注销时调用的函数将是stop();。 And just in case someone wanted to suggest it, I can't use GeoSense. 万一有人要提出建议,我就不能使用GeoSense。

Old question but here goes anyway: 老问题了,但还是这样:

I think your answer is not a problem with the sensor but with the scope of the watcher variable. 我认为您的答案不是传感器问题,而是watcher变量的范围。 You start the watcher then register for the event and then your watcher losses scope. 您启动观察者,然后注册该事件,然后观察者损失范围。

GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();

public string check(string stop)
{
   watcher.Start();...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM