添加一个路由到MKMapView [英] Adding a route to a MKMapView

查看:143
本文介绍了添加一个路由到MKMapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将路由功能添加到正在处理的应用中。我发现Craig Spitzkoff的文章,介绍如何在 MKMapView上画线这很好用。但是因为我没有像预期那样帮助我的道路上的点的坐标。有什么办法可以确定给定点之间的坐标,比如说我的当前位置和另一个地址吗?

I'm trying to add a routing feature to an app I'm working on. I found Craig Spitzkoff's article on how to draw lines on an MKMapView which works pretty good. But since I don't have the coordinates of the points on the roads that doesn't help me as expected. Is there any way to determine the coordinates between to given points, say my current position and another address?

推荐答案

基本上你需要制作 HTTP请求添加到 Google路线API 。服务条款规定您必须在谷歌地图上显示结果,但我认为,因为您使用的是MKMapView,所以您会没事的:

Basically you will need to make an HTTP request to the Google Directions API. The terms of service state that you have to display the results on a Google map, but I think because you are using an MKMapView, you will be fine:


路线API只能与在Google地图上显示结果一起使用;禁止使用路线数据而不显示要求提供路线数据的地图。

the Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited.

查看路线申请,了解您需要在网址上传递的参数详情:

Check out the Directions Request for details on the parameters you will need to pass on the URL:


http ://maps.google.com/maps/api/directions/output?parameters

http://maps.google.com/maps/api/directions/output?parameters

您取回的数据将 JSON XML 取决于你的要求( output ),所以你需要解析它以得到描述点的集合方向。

The data you get back will be JSON or XML depending on what you asked for (output), so you will need to parse that to get the set of points describing the directions.

这篇关于添加一个路由到MKMapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆