如何获取地图上两点之间的路线方向以绘制行车路线?

发布于 2024-08-07 23:03:17 字数 243 浏览 7 评论 0原文

有没有办法使用核心位置或谷歌或其他一些API来提供地图上的两个点并获取路线的纬度/经度对的结果集?

我在本教程中看到在 MKMapView 上绘制折线或路线如何绘制行驶方向使用核心图形...但在示例代码中它有route.csv,它具有预定义的经度和纬度集...我如何制作一对经度和纬度以便我可以绘制行车方向。

is there a way to use core location or google or some other api to provide two points on the map and get the resulting set of latitude/longitude pairs for the route?

i have seen in this tutorial Drawing polyines or routes on a MKMapView that how to draw driving direction using core graphics...but in the sample code it has route.csv which has predefined set of longitudes and latitudes.....how do i make pair of longitudes and latitudes so that i can draw driving directions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一绘本一梦想 2024-08-14 23:03:17

公司投资数百万美元来开发路由算法,所以我非常怀疑你是否能够在任何地方免费获得它(不过我很高兴我错了)。例如,Google Maps JavaScript API 支持路由,所以我猜你可以破解它。请注意,结果不会很快漂亮。

Companies invest millions of dollars into developing routing algorithms, so I very much doubt that you'll be able to get it for free anywhere (I'm happy to be wrong, though). For example, the Google Maps JavaScript API supports routing, so I guess you could hack that up. The results wouldn't be fast or pretty, mind you.

人│生佛魔见 2024-08-14 23:03:17

如果您对路线请求的使用有限(每天少于一定数量)并且始终在 Google 地图上显示结果,则您确实有资格使用免费的 Google Directions API。

https://developers.google.com/maps/documentation/directions/

阅读彻底许可部分以了解其限制。您应该能够轻松请求 json 响应,该响应比 xml 响应更容易解析(加上 Apple 在 iOS 中添加了 json 解析器)。

例如

http://maps.googleapis.com/maps/api/directions/json?origin=波士顿,马萨诸塞州&目的地=康科德,马萨诸塞州&waypoints=查尔斯敦,马萨诸塞州|列克星敦,马萨诸塞州&sensor=false

如果超出限制,您应该查看他们的营业执照。

If you have a limited use of the directions request (less than a certain amount per day) and always display results on a Google map, you do qualify for the free Google Directions API.

https://developers.google.com/maps/documentation/directions/

Read the license part thoroughly to know the limits. You should easily be able to request a json response that will b easier to parse than an xml one (plus Apple added json parser in iOS).

For example

http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false

If you are over the limit, you should look into their business licenses.

玉环 2024-08-14 23:03:17

老问题,但 MTDirectionsKit 最近开源并且效果很好:

MTDirectionsKit

Old question but MTDirectionsKit was recently open sourced and it works great:

MTDirectionsKit

殤城〤 2024-08-14 23:03:17

使用Google API,您可以从两个点获取路线,唯一的问题是如果您不付费,您每天只能使用一次。

从google上搜索如何获取关键API,youtube上有很多视频在谈论它。

此外,我有一个库可以帮助您在点之间画线这个 https://github.com/jd-alexander/Google-Directions-Android

build.gradle(Module:app) 中实现后,实现 library

public class LocationMapActivity extends AppCompatActivity Implements RoutingListener

会出现实现方法的错误(必须实现它们,但没有必要<强>使用它们)。

我刚刚这样做了:

 public void route(){

       Routing routing = new Routing.Builder()
                    .travelMode(/* Travel Mode */)
                    .withListener(/* Listener that delivers routing results.*/)
                    .waypoints(/*waypoints*/)
                    .key(/*api key for quota management*/)
                    .build();
        routing.execute();
    }

链接中的更多信息。

with Google API you can get directions from two points, the only problem is you just can use it once a day if you don't pay.

Search how to get the key API from google, there are a lots of videos on youtube talking about it.

Furthemore, i got a library which hepls you to draw the line between points this one https://github.com/jd-alexander/Google-Directions-Android

After you implemented it in build.gradle(Module:app), implement the library in the class like

public class LocationMapActivity extends AppCompatActivity implements RoutingListener

will appear a error to implemets the methods (obligatory to implement them but It's not necessary to use them).

I just did this:

 public void route(){

       Routing routing = new Routing.Builder()
                    .travelMode(/* Travel Mode */)
                    .withListener(/* Listener that delivers routing results.*/)
                    .waypoints(/*waypoints*/)
                    .key(/*api key for quota management*/)
                    .build();
        routing.execute();
    }

More info in the link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文