4

I want to figure out how Google Map's API to give us directions.

Create a sample tool where I can use my location as a starting point and choose another location and I can view directions (both driving and walking) in text and on map within my existing application.

I haven't used google map api so I am completely naive about this

can anyone help me with this?

Jean-Luc Godard
  • 1,873
  • 3
  • 28
  • 53

1 Answers1

2

try this,

NSString *urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%f,%f&daddr=%f,%f",sourcelocation.latitude,sourcelocation.longitude,destinationlocation.latitude,destinationlocation.longitude];

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];

What the code do is, it will show the route between your source and destination location on google map.

If you dont have the longitude then you can do it like:-

 NSString *source=@"NorthCarolina";
    NSString *destination=@"SouthCarolina";

    NSString *urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%@&daddr=%@",source,destination];

    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];

I hope this will help you.Happy coding:)

Gypsa
  • 11,230
  • 6
  • 44
  • 82
  • hey Gypsa..do this thing is supported by iphone ??and I got this from somewhere....this is according to new api as they say...should i use this ? https://github.com/kishikawakatsumi/MapKit-Route-Directions – Jean-Luc Godard Jun 13 '11 at 07:26
  • Yes this is supported by iphone and for this code you need not to include any specific framework.Just add two lines code.It will open your google map with directions of your source and destination location. – Gypsa Jun 13 '11 at 07:29
  • @zoozoo I have run this code on my iphone it is working perfectly.try it – Gypsa Jun 13 '11 at 07:32
  • and I need to find directions for both driving and walking things..what should i do for that? – Jean-Luc Godard Jun 13 '11 at 07:32
  • @zoozoo NSString *source=@"NorthCarolina"; NSString *destination=@"SouthCarolina"; NSString *urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%@&daddr=%@",source,destination]; [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]]; – Gypsa Jun 13 '11 at 07:34
  • this one you can give your source location and destination location and check it. – Gypsa Jun 13 '11 at 07:34
  • yes i am getting it but what to do for this driving and walking thing? – Jean-Luc Godard Jun 13 '11 at 07:41
  • @zoozoo you have to click on button of direction of car,walking route etc you can click them and find the routes. – Gypsa Jun 13 '11 at 07:58