向 MKMapView 添加路线 [英] Adding a route to a MKMapView

查看:32
本文介绍了向 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.服务条款规定您必须在 Google 地图上显示结果,但我认为因为您使用的是 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:

Directions 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.

查看路线请求,了解有关参数的详细信息您需要传递 URL:

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/输出?参数

您返回的数据将是 JSONXML 取决于您的要求(输出),因此您需要对其进行解析以获取描述方向的点集.

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天全站免登陆