Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 views
in Technique[技术] by (71.8m points)

iphone - Adding a route to a 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...