Question

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?

Was it helpful?

Solution

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:)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top