MKMapView Route/Directions
Asked Answered
P

2

12

I found that the Google Maps API supports Directions through:

var map;
var directionsPanel;
var directions;

function initialize() {
  map = new GMap2(document.getElementById("map_canvas"));
  directionsPanel = document.getElementById("my_textual_div");
  map.setCenter(new GLatLng(49.496675,-102.65625), 3);
  directions = new GDirections(map, directionsPanel);
  directions.load("from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)");
}

So how can this be translated into Objective-C so it can be retrieved by the iPhone? I know how to draw a line on MKMapView I just need the geolocations for the route.

Or perhaps there is a different way to get the route between two geolocation points.

Please let me know,

Thanks in advance.

Phooey answered 29/9, 2009 at 20:44 Comment(0)
C
9

There is an undocumented Google Maps Directions API mentioned and exposed here

Also you should take a look at the sample IPhone application which draws routes/directions onto MKMapView using the API mentioned above here

But warning you about the licencing issues about the undocumented Google Maps Directions API.

Hope this helps.

Coryden answered 31/5, 2010 at 6:49 Comment(3)
-- NOTICE -- Please find sample project at github https://github.com/kadirpekel/MapWithRoutesCoryden
the links at both "here" are not working when I clicked before a minute while writing this comment. Please check are they working or not and update them.. because I am indeed of them...Calida
using google maps APi works only while using Google maps, this seems no longer a trustable method as iOS 5 wont allow this, need a better methods.Please post if anyone finds any.Molarity
V
8

I was originally going to say (and I'm sure others will bring it up) that the Google Maps terms-of-use says you can't use directions if you plan to use MapKit. But then I double-checked http://code.google.com/apis/maps/terms/iPhone.html and couldn't really find an explicit restriction. If I understand it correctly, it actually says you can't use directions as long as it's tied to a GPS-driven realtime turn-by-turn functionality. You should use your own judgement as to whether it's OK or not and whether it affects your chance of acceptance on the AppStore.

As far as getting the actual data in Objective-C your best best is to look at the Google Ajax search documentation [ http://code.google.com/apis/ajaxsearch/documentation/ ] especially the section under Flash and other Non-Javascript Environments. It explains a RESTful API where you can send HTTP GET requests to Google and get JSON data back. That's the only way I've found to get programmatic data out of Google that isn't tied to Javascript.

Once you've figured out the proper URL to invoke you can wrap the whole thing in an ASIHTTPRequest call and feed the result to a JSON parser. One thing to keep in mind is that the RESTful API returns only a few results (between 4 and 8) at a time and you have to keep going back until you've got all the data. There also appears to be a 64-item cap to the number of results returned by the API so some complex edge-cases may be affected.

Vercingetorix answered 29/9, 2009 at 21:42 Comment(1)
I think it's weird they support almost anything except directions. Oh well I'll guess I am better of using a forward to the actual google maps app.Phooey

© 2022 - 2024 — McMap. All rights reserved.