Reputation: 4245
In my app there is a contact us view that will have a button to open the company's address. So My code works fine in iOS6 and I know it should be different for iOS 5 but couldn't find the proper way to do it. Here is my code:
// Check for iOS 6
BOOL iOS6 = NO;
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
iOS6 = YES;
switch (buttonIndex) {
case 0:
if (iOS6)
{
// Create an MKMapItem to pass to the Maps app
CLLocationCoordinate2D coordinate =
CLLocationCoordinate2DMake(26.375561, 50.170305);
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate
addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:@"Industrial Projects Technologies"];
// Pass the map item to the Maps app
[mapItem openInMapsWithLaunchOptions:nil];
}
else
{
// Use the iOS 5 method
}
break;
Upvotes: 1
Views: 780
Reputation: 290
Use this code for iOS5 for showing source to destination route
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.apple.com/?daddr=%@,%@&saddr=%@,%@",latitudeOfDestinationLocation,longitudeOfDestinationLocation,latitudeOfSourceLocation,longitudeOfSourceLocation]]];
To show particular point in map
maps.google.com/?q=latitude,longitude
Example: maps.google.com/?q=26.375561,50.170305
You can also refer to this link.
Upvotes: 4