在Windows Phone 8.1 winrt(MapRouteFinder.GetDrivingRouteAsync)中查找多个记录中的两个coordiantes之间的距离 [英] Finding distance between 2 coordiantes of many records at once not working in windows phone 8.1 winrt (MapRouteFinder.GetDrivingRouteAsync)

查看:52
本文介绍了在Windows Phone 8.1 winrt(MapRouteFinder.GetDrivingRouteAsync)中查找多个记录中的两个coordiantes之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个移动服务,它为所有记录提供具有纬度和经度的'n'记录,因此我需要计算用户当前位置与记录中的值之间的距离。


当计算距离小于10的记录很少时,但是当记录数超过10时,可能会记录20条记录,那么只计算一些记录并给出距离。


下面是我用来计算2个坐标之间距离的代码。我创建了一个示例应用程序,只需要执行和测试,我已经上传到skydrive并共享链接。那么有人可以帮我解决这个
问题。


http://1drv.ms/1sgvLWZ

 this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,async()=> 
{
BasicGeoposition endLocation = new BasicGeoposition();
endLocation.Latitude = doctor.Latitude;
endLocation .Longitude = doctor.Longitude;
Geopoint endPoint = new Geopoint(endLocation);

MapRouteFinderResult routeResult = null;

for(int i = 0; i< ; 12; i ++)// 12尝试
{
routeResult = await MapRouteFinder.GetDrivingRouteAsync(startPoint,endPoint,MapRouteOptimization.Time,MapRouteRestrictions.None);

if(routeResult。状态== MapRouteFinderStatus.Success)
{
doctor.Distance =(routeResult.R oute.LengthInMeters / 1000).ToString(" F")+" KMS英寸;
tb.Text = doctor.Distance;
routeResult = null;
休息;
}
}

if(string.IsNullOrEmpty(tb.Text)== true)
tb.Text =" ---" ;;

});

解决方案

您好Sharathm1,


当我在项目中添加一些调试代码片段时,我发现该项目有效。我取消评论使用大约30多条记录进行测试。结果是我无法使用您的项目重现您的问题。您可以尝试下面的代码。

 if(routeResult.Status == MapRouteFinderStatus.Success)
{
doctor.Distance =(routeResult。 Route.LengthInMeters / 1000).ToString(" F")+" KMS英寸;
Debug.WriteLine(string.Format(" {0},尝试:{1},结果:{2}",doctor.Name,i + 1,doctor.Distance));
tb.Text = doctor.Distance;
routeResult = null;
休息;
}
else {
Debug.WriteLine(string.Format(" {0},尝试:{1},结果:失败",doctor.Name,i + 1));
}


Windows中的网络或线程资源可能存在问题电话,您是否尝试过减少同时执行的任务量?例如,您想要计算30条记录,将
分成三组,然后在后台逐一计算该组。


我的测试结果:


https://onedrive.live.com/redir?resid=CA34FEE4EB628008%21232


问候,


I have a mobile service which gives 'n' of records which has Latitude and Longitude for all the records so i need to calculate the distance between the user current location and the value which is there in records.

When there are few records around less than 10 distance is calculated but when there are more than 10 may be 20 records then only some records will be calculated and given the distance.

Below is the code which i am using to calculate the distance between 2 coordinates. I have created a sample app which just needs to be executed and tested which i have uploaded to the skydrive and sharing the link. So can someone please help me solve this problem.

http://1drv.ms/1sgvLWZ

            this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
            {
                BasicGeoposition endLocation = new BasicGeoposition();
                endLocation.Latitude = doctor.Latitude;
                endLocation.Longitude = doctor.Longitude;
                Geopoint endPoint = new Geopoint(endLocation);

                MapRouteFinderResult routeResult = null;

                for (int i = 0; i < 12; i++)        // 12 Attempts
                {
                    routeResult = await MapRouteFinder.GetDrivingRouteAsync(startPoint, endPoint, MapRouteOptimization.Time, MapRouteRestrictions.None);

                    if (routeResult.Status == MapRouteFinderStatus.Success)
                    {
                        doctor.Distance = (routeResult.Route.LengthInMeters / 1000).ToString("F") + " Kms";
                        tb.Text = doctor.Distance;
                        routeResult = null;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(tb.Text) == true)
                    tb.Text = "---";

            });

解决方案

Hi Sharathm1,

When I added some debug code snippet in your project, I just found that the project worked. I uncommented to use about 30+ records for test. The result was that I could not reproduce your issue using your project on my side. You can try the code below.

if (routeResult.Status == MapRouteFinderStatus.Success)
                    {
                        doctor.Distance = (routeResult.Route.LengthInMeters / 1000).ToString("F") + " Kms";
                        Debug.WriteLine(string.Format("{0}, attemps:{1},result:{2}", doctor.Name, i + 1, doctor.Distance));
                        tb.Text = doctor.Distance;
                        routeResult = null;
                        break;
                    }
                    else {
                        Debug.WriteLine(string.Format("{0}, attemps:{1},result:fail", doctor.Name, i + 1));
                    }

There might be the problem about network or threading resources in windows phone, have you tried to reduce the amount of task executing at the same time? For example, you want to calculate 30 records, divide into three groups and then calculate the group one by one in background.

My test result:

https://onedrive.live.com/redir?resid=CA34FEE4EB628008%21232

Regards,


这篇关于在Windows Phone 8.1 winrt(MapRouteFinder.GetDrivingRouteAsync)中查找多个记录中的两个coordiantes之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆