user2431727
user2431727

Reputation: 907

How to calculate coordinates between the start coordinate and the end coordinate - uwp c#

In My Map Control, I want to move a bus through given bus stops. For that I have drawn route through given stops. Now I want to move the bus through this route. For a smoother rendering of bus through the path, I have to find multiple locations between start coordinates and end coordinates. And those locations should have road transportation. How can I achieve it? These are the four stops.

 Geopath path = new Geopath(new List<BasicGeoposition>(){
        new BasicGeoposition()
        {
            Latitude= 1.2989658333333334, Longitude=103.8004543333333
        } ,  
       new BasicGeoposition()
        {
            Latitude=1.3027026666666668, Longitude=103.80124616666667
        } ,     
       new BasicGeoposition()
        {
            Latitude=1.3062241666666665, Longitude=103.80175516666667
        } ,   
       new BasicGeoposition()
        {
            Latitude=1.3087055, Longitude=103.8026675
        } 
    }
 );

Upvotes: 2

Views: 631

Answers (1)

Serve Laurijssen
Serve Laurijssen

Reputation: 9763

You can use:

MapRouteFinder.GetDrivingRouteAsync(Geopoint, Geopoint)

Pass in the start and end location and it returns a MapRouteFinderResult object.

BasicGeoposition startLocation = new BasicGeoposition() {Latitude=47.643,Longitude=-122.131};

// End at the city of Seattle, Washington.
BasicGeoposition endLocation = new BasicGeoposition() {Latitude = 47.604,Longitude= -122.329};

// Get the route between the points.
MapRouteFinderResult routeResult =
     await MapRouteFinder.GetDrivingRouteAsync(
     new Geopoint(startLocation),
     new Geopoint(endLocation),
     MapRouteOptimization.Time,
     MapRouteRestrictions.None);
  • MapRouteFinderResult has a 'Route' property of type MapRoute.
  • MapRoute has a 'Path' property of type GeoPath.
  • And GeoPath has a 'Positions'property of type IReadOnlyList which gives you your coordinates.

The complete example can be found here:

https://learn.microsoft.com/nl-nl/windows/uwp/maps-and-location/routes-and-directions

Upvotes: 1

Related Questions