iPhone App :show direction using Map
in My iPhone App How Can I show directions from current location to End Point?
is there any built in component or facility available o开发者_C百科n iphone which can show maps and direction using GPS and built in compass?
If you mean taking the user to the maps application based on two points, then you can do it like this:
- Create an NSURL that looks like this:
NSURL *URL = [NSURL URLWithString:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"];
You plug in your starting address and destination (in lat. and long.) appropriately. - Tell your application to open the URL
[[UIApplication sharedApplication] openURL:URL];
It should take you to the maps application automatically!
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]];
NSString *Urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%@&daddr=%@",from_address,to_address];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];
This will give clear direction mentioning the source address and destination address.
精彩评论