113*_*408 6 ios directions mapbox swift mapbox-gl
我一直在使用Mapbox为我的应用程序生成路线和转弯导航,它运行良好.但是我想避免通过路线的某些坐标,但我无法弄明白.
获取路线的代码:
Directions.shared.calculate(options) { [unowned self] (waypoints, routes, error) in
// Take first route and customize it in a way to get around some coordinates
}
Run Code Online (Sandbox Code Playgroud)
这是一个场景:
1-用户位置是 latitude = 37.332331410000002, longitude = -122.0312186
2-用户将要Santa Clara Unified School找到latitude = 37.354100000000003,longitude = -121.9552
3- Api生成以下路径:
[0] = {
latitude = 37.332329999999999
longitude = -122.03118000000001
}
[1] = {
latitude = 37.332619999999999
longitude = -122.03118000000001
}
[2] = {
latitude = 37.332609999999995
longitude = -122.03097000000001
}
[3] = {
latitude = 37.332609999999995
longitude = -122.03076000000001
}
[4] = {
latitude = 37.332199999999993
longitude = -122.03076000000001
}
[5] = {
latitude = 37.331689999999995
longitude = -122.03076000000001
}
[6] = {
latitude = 37.331689999999995
longitude = -122.03190000000002
}
[7] = {
latitude = 37.331719999999997
longitude = -122.03199000000002
}
[8] = {
latitude = 37.331759999999996
longitude = -122.03205000000003
} ...
Run Code Online (Sandbox Code Playgroud)
4-假设生成的路线经过East Homestead Rd,我希望能够避开这条路并产生一条新的路线,即使它是一条较长的路线.在下面的屏幕中,避免路线为红色,因为经过East Homestead Rd和乘坐未通过East Homestead Rd的下一条最快路线

任何帮助,将不胜感激 !
编辑:这是查询路线是否有要避免的点的查询
// $linestring is the array of coordinates from the route in the string format of (lng lat,lng2 lat2,lng3 lat3,lng4 lat4....)
$query = $this->em->createQuery('
SELECT count(i) as counter
FROM HitsBundle:Hit i
WHERE i.datetime BETWEEN :lastMonth AND :now
AND
MBRCovers(
ST_Buffer(
ST_GeomFromText(\'LineString('.$linestring.')\') ,
0.00001
),
i.coordinates
) = 1
GROUP BY i.coordinates
HAVING counter > 1
')
->setParameter('lastMonth', $lastMonth)
->setParameter('now', new \DateTime())
->setMaxResults(1);
Run Code Online (Sandbox Code Playgroud)
我可能在这里粗略猜测,但是通过 Mapbox API 来看,它在生成路线时没有任何可以避免的选项,因此您需要在客户端实现一些路线选择逻辑。
基本上,您需要有一个算法来获取一组要避免的点,并检查您的路线几何图形 GeoJSON 或折线是否在给定点的某个阈值范围内。如果是 - 丢弃该路由(或降低路由优先级)。
当然,如果 Mapbox 提供的所有路线都被丢弃,则可能无法找到路线 - Mapbox 不知道您的限制,因此使用路线权重可能是解决此问题的一种选择。
这些帖子可能会给您一些提示:
| 归档时间: |
|
| 查看次数: |
909 次 |
| 最近记录: |