简体   繁体   中英

How can i turn on & off gps in WP7, when my app is on & off?

我正在开发应用程序,我需要打开和关闭GPS,意味着当用户打开我的应用程序然后gps开始工作,当关闭应用程序时,gps自动关闭。

If you mean ' how do I turn the GPS on/off in my app, even if the user has it off in Settings? ', you can't. The user must opt to enable the GPS themselves first, then (according to marketplace rules) you must ask them if you can use GPS functions, AND there must be a way for them to turn GPS off for your app, inside your app.

If you're just asking how you can use the GPS, the class you want is GeoCoordianteWatcher

The simplest way to use it is:

var watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.Start();

Although looking into the Reactive ways to use it isn't a bad idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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