question

Roy-6675 avatar image
0 Votes"
Roy-6675 asked IoTGirl answered

Unexpected restult when querying walking route

Hi everyone,

I am trying to use the route function of the Bing map (Wuxi - Shanghai) . When I tried to find the route data when calling MapRouteFinder.GetWalkingRouteAsync() Method, the MapRouteFinderResult is giving me a NoRouteFoundWithGivenOptions status.

To confirm if this issue is related to the location, I tried to get some other route data like New York to San Francisco, or The White House to Statue of Liberty National Monument. But the MapRouteFinderResult failed again and it gives me the StartPointNotFound status.

This is the code I'm using

 private async void MainPage_Loaded(object sender, RoutedEventArgs e)
         {
    
             BasicGeoposition cityPosition = new BasicGeoposition() { Latitude = 31.2304, Longitude = 121.4737 };
             Geopoint cityCenter = new Geopoint(cityPosition);
    
             MapControl1.Center = cityCenter;
             //other information
             MapControl1.ZoomLevel = 11;
             MapControl1.LandmarksVisible = true;
             Geopoint MyLoc = null;
             var accessStatus = await Geolocator.RequestAccessAsync();
    
             switch (accessStatus)
             {
                 case GeolocationAccessStatus.Allowed:
                     Geolocator geolocator = new Geolocator();
                     Geoposition pos = await geolocator.GetGeopositionAsync();
                     //get my position
                     MyLoc = pos.Coordinate.Point;
                     break;
                 case GeolocationAccessStatus.Denied:
                     break;
                 case GeolocationAccessStatus.Unspecified:
                     break;
             }
             MapIcon mapIcon1 = new MapIcon();
             mapIcon1.Location = cityCenter; 
             mapIcon1.NormalizedAnchorPoint = new Windows.Foundation.Point(1.0, 1.0);
             mapIcon1.Title = "万达";
             mapIcon1.ZIndex = 0;
             mapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/StoreLogo.png")); 
             MapRouteFinderResult routeResult = await MapRouteFinder.GetWalkingRouteAsync(MyLoc, cityCenter); 
    
   
             if (routeResult.Status == MapRouteFinderStatus.Success)
             {
                 double length = routeResult.Route.LengthInMeters;
                 //distance
                 string Tb_Distance = length < 1000 ? length.ToString() + "m" : (length / 1000).ToString("0.00") + "km";
                 //time
                 string Tb_Time = routeResult.Route.EstimatedDuration.TotalMinutes.ToString("0.00") + "分钟";
    
                 //show the route
                 MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
                 viewOfRoute.RouteColor = Windows.UI.Color.FromArgb(255, 26, 188, 156);
                 MapControl1.Routes.Clear();
                 MapControl1.Routes.Add(viewOfRoute);
                 await MapControl1.TrySetViewBoundsAsync(
                 routeResult.Route.BoundingBox,
                 null,
                 Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None);
             }
         }

Question:

Why I can't get the correct route data? Is there something I'm missing?

windows-maps
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It's difficult to say without knowing what position is being passed in to MyLoc relative to the destination you have, but it's probably due to the position not being close to any part of the routable network, or being too far from the destination (walking routes longer than a certain distance are not supported - walking routes from New York to San Francisco would not be supported for example).
I notice the position being used for cityCenter happens to be in China. If you're dealing with positions in China, there are extra steps you have to deal with due to government restrictions. All map data in China is shifted by a government mandated algorithm. If you get a raw GPS position, you will need to adjust that to match the routing network before calling any of the services APIs.

1 Vote 1 ·

1 Answer

IoTGirl avatar image
0 Votes"
IoTGirl answered

Hi Roy,

Further to Duncan's answer, if you put that same location in the consumer page at Bing.com/maps, what happens? Does the location look "Routeable"? Did Bing Maps change your location to move it to a nearby spot to accommodate? Can you get the expected route to work in the Bing Maps consumer experience?

Sincerely,
IoTGirl

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.