我想编写一个程序,该程序可以使用OSM和库Itinero(http://www.itinero.tech/)计算从A点到B点的行驶时间
当前我正在执行以下操作:
在代码中使用routerdb文件,如以下代码片段所示:
RouterDb routerDb = new RouterDb();
string path = "PathToRouterDB";
using (var stream = new FileInfo(path).OpenRead())
{
routerDb = RouterDb.Deserialize(stream);
}
router = new Router(routerDb);
var profile = router.Db.GetSupportedProfile("car");
Coordinate from = new Coordinate(fromLatidutde, fromLongitude);
Coordinate to = new Coordinate(toLatitude, toLongitude);
List<RouterPoint> points = new List<RouterPoint>
{
router.TryResolve(profile, from, 200),
router.TryResolve(profile, to, 200)
}
var route = router.TryCalculate(profile, points.ToArray());
float drivingTime = route.Value.TotalTime;
这是正确的方法吗?当我计算远距离(例如500公里)时,要花5分钟才能计算出行驶时间,这对我的程序来说太过分了。
如果有人对我有建议,那就太好了!
最好的问候, 安德烈亚斯(Andreas)
答案 0 :(得分:0)
您的代码正确。您只需要添加以下内容: routerDb.AddContracted(profile); 在我的PC上,它会计算3-4秒的相似距离。