Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 8 Windows Phone:位置已更改,未启动Windows 8_Windows Phone 8_Location_Windows Phone 8.1 - Fatal编程技术网

Windows phone 8 Windows Phone:位置已更改,未启动Windows 8

Windows phone 8 Windows Phone:位置已更改,未启动Windows 8,windows-phone-8,location,windows-phone-8.1,Windows Phone 8,Location,Windows Phone 8.1,我在使用windows phone时遇到问题,我发现一个geolocator位置更改事件,我实例化并设置geolocator,如下所示: geolocator = new Geolocator(); geolocator.DesiredAccuracy = PositionAccuracy.High; geolocator.MovementThreshold = 100; // The units are meters. geolocator.PositionChanged += geo

我在使用windows phone时遇到问题,我发现一个geolocator位置更改事件,我实例化并设置geolocator,如下所示:

 geolocator = new Geolocator();
 geolocator.DesiredAccuracy = PositionAccuracy.High;
 geolocator.MovementThreshold = 100; // The units are meters.
 geolocator.PositionChanged += geolocator_PositionChanged;
我的职位变更事件如下:

void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
    {
        Dispatcher.BeginInvoke(() =>
        {
            marker = (UserLocationMarker)this.FindName("UserLocationMarker");
            if (marker != null)
            {
                marker.GeoCoordinate = args.Position.Coordinate.ToGeoCoordinate();

            }

        });
    }
当我在仿真器中启动此命令时,正确更改的位置将被触发1次,最后一个位置输入到工具函数中的位置中。。。但是我添加到定位工具的任何后续地质点都不会触发positionchanged方法。。。。我不认为这是仿真器本身,就好像我在仿真器上启动地图并正确地使用位置工具一样,它会随着每次更新而更改用户位置。但在我的代码中,我对positionchanged方法进行了调试,它只在应用程序第一次启动时被调用,仅此而已。。。一旦得到了地理位置,她就写了这些。。切勿在“位置”工具中对任何操作触发


我的代码中没有任何东西会破坏geolocator对象。。。但是没有其他的输入触发它。。。我不知所措。。对于我所缺少或不理解的任何帮助,我们将不胜感激。此时,我想知道工具箱中的UserLocationMarker是否以某种方式破坏或删除了位置更改事件侦听器注册或其他内容。

参考此参考以正确响应位置更改事件:

确保在UI线程上声明地理定位器。我在我的WindowsPhone8上测试了以下代码。我在办公室里走来走去,看着按钮的内容随着我在大楼里的位置而变化

可能是您的MovementThreshold太高或模拟器出现故障

public partial class MainPage : PhoneApplicationPage
{    
    Geolocator geo = null;
    public MainPage()
    {
        InitializeComponent();
        geo = new Geolocator();
        try
        {
            geo.MovementThreshold = 1.0;
            geo.DesiredAccuracy = PositionAccuracy.High;
            geo.ReportInterval = 2000;
            geo.PositionChanged += geo_PositionChanged;
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }

    private void geo_PositionChanged(Geolocator sender, PositionChangedEventArgs e)
    {
        // my_button is just a normal button on the main xaml page
        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            this.my_button.Content = e.Position.Coordinate.Latitude.ToString() + "\n" + e.Position.Coordinate.Longitude.ToString();
        });
    }
}
首先检查以获取有关如何测试使用位置服务的应用程序的更多知识


关于你的信息,这个问题已经有了答案。希望有帮助。

这段代码对我来说很好用,效果很好,类似于heremaps应用程序:

geolocator = new Geolocator();
geolocator.DesiredAccuracy = PositionAccuracy.High;
geolocator.ReportInterval = 2000;
geolocator.PositionChanged += geolocator_PositionChanged;
不管你离上次抓到的位置有多远,2秒后,应用程序将再次抓到你当前的位置 尝试在真实设备上测试应用程序