本文介绍了返回的Windows Phone 7从GeoCoordinateWatcher.StatusChanged事件的位置数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Windows Phone应用程序,我需要得到用户的位置。我想这在一个很好的方式(以及尽我所能),使用一个单独的类在那里我查询 GeoCoordinateWatcher 位置数据和数据恢复调用方法。



现在的问题是,我不知道如何返回的 LocationData 结构来调用从的 GeoCoordinateWatcher StatusChanged 事件的方法。看到代码和放大器;评论:

 公共结构LocationData 
{
公共字符串纬度;
公共字符串经度;
}


公共类LocationService:GeoCoordinateWatcher
{
私人GeoCoordinateWatcher守望者;

私人LocationData StartLocationWatcher()
{
LocationData LD =新LocationData();

//监视器可以变以前声明为类型GeoCoordinateWatcher。
如果(观察者== NULL)
{
观察家=新GeoCoordinateWatcher(GeoPositionAccuracy.High);
}

watcher.MovementThreshold = 20; //使用MovementThreshold忽略信号中的噪声。

watcher.StatusChanged + =(0,参数)=>
{
开关(args.Status)
{
情况下GeoPositionStatus.Ready:
//使用GeoCoordinateWatcher对象的位置属性来获取当前位置。
会有地理座标共同= watcher.Position.Location;

ld.latitude = co.Latitude.ToString(0.000);
ld.longitude = co.Longitude.ToString(0.000);

//停止定位服务,以节省电池电量。

watcher.Stop();
中断;
}
};

watcher.Start();
返回LD; //需要这个返回到调用方法,从GeoCoordinateWatcher
}
}

$ B $采取经纬度数据b

解决方案

我不知道,如果这是你追求的。



注册PositionChanged事件:



GeoCoordinateWatcher.PositionChanged + = GeoCoordinateWatcherPositionChanged;

 私人无效GeoCoordinateWatcherPositionChanged(对象发件人,GeoPositionChangedEventArgs<&会有地理座标GT; E)
{
VAR currentLatitude = e.Position.Location.Latitude;
VAR currentLongitude = e.Position.Location.Longitude;
}

的。


I'm writing a Windows Phone app where I need to get user's location. I'm trying to this in a nice way (well as much as I can), using a separate class where I'm querying GeoCoordinateWatcher for location data and return that data to calling method.

The problem is, I don't know how to return the the LocationData struct to the calling method from the StatusChanged event of the GeoCoordinateWatcher. See the code & comments:

public struct LocationData
{
    public string latitude;
    public string longitude;
}


public class LocationService : GeoCoordinateWatcher
{
    private GeoCoordinateWatcher watcher;

    private LocationData StartLocationWatcher()
    {
        LocationData ld = new LocationData();

        // The watcher variable was previously declared as type GeoCoordinateWatcher.
        if (watcher == null)
        {
            watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
        }

        watcher.MovementThreshold = 20; // Use MovementThreshold to ignore noise in the signal.

        watcher.StatusChanged += (o, args) =>
            {
                switch (args.Status)
                {
                    case GeoPositionStatus.Ready:
                       // Use the Position property of the GeoCoordinateWatcher object to get the current location.
                       GeoCoordinate co = watcher.Position.Location;

                       ld.latitude = co.Latitude.ToString("0.000");
                       ld.longitude = co.Longitude.ToString("0.000");

                       //Stop the Location Service to conserve battery power.

                       watcher.Stop();
                       break;
               }
           };

        watcher.Start();
        return ld; //need to return this to the calling method, with latitude and longitude data taken from GeoCoordinateWatcher
    }
}
解决方案

I'm not sure if this is what you're after.

Register the PositionChanged event:

GeoCoordinateWatcher.PositionChanged += GeoCoordinateWatcherPositionChanged;

private void GeoCoordinateWatcherPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    var currentLatitude = e.Position.Location.Latitude;
    var currentLongitude = e.Position.Location.Longitude;
}

More on when PositionChanged will fire.

这篇关于返回的Windows Phone 7从GeoCoordinateWatcher.StatusChanged事件的位置数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:31