SORU
19 EYLÜL 2012, ÇARŞAMBA


Program aracılığıyla iOS 6 app Haritalar açık

Bu (Google Maps uygulamasını açmak gibi bir önceki iOS 6, bir açılış URL:

NSURL *url = [NSURL URLWithString:@"http://maps.google.com/?q=New York"];
[[UIApplication sharedApplication] openURL:url];

Şimdi yeni Apple Haritalar uygulaması ile, bu sadece Google Maps için Mobil Safari açılır. Nasıl iOS 6 ile aynı davranışı başarabilir miyim? Nasıl açık Haritalar uygulaması programlı ve belirli bir konuma işaret var//Adres arama/ne olursa olsun?

CEVAP
15 EKİM 2012, PAZARTESİ


İşte resmi Apple yolu:

// Check for iOS 6
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) 
{
    // Create an MKMapItem to pass to the Maps app
    CLLocationCoordinate2D coordinate = 
                CLLocationCoordinate2DMake(16.775, -3.009);
    MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate 
                                            addressDictionary:nil];
    MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
    [mapItem setName:@"My Place"];
    // Pass the map item to the Maps app
    [mapItem openInMapsWithLaunchOptions:nil];
}

Eğer ya da konuma talimatları sürüş mesafesinde elde etmek istiyorsanız, openMapsWithItems:launchOptions: dizi MKMapItem mapItemForCurrentLocation donanım ve piyasaya uygun seçenekleri ayarlayabilirsiniz.

// Check for iOS 6
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) 
{
    // Create an MKMapItem to pass to the Maps app
    CLLocationCoordinate2D coordinate = 
                CLLocationCoordinate2DMake(16.775, -3.009);
    MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate 
                                            addressDictionary:nil];
    MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
    [mapItem setName:@"My Place"];

    // Set the directions mode to "Walking"
    // Can use MKLaunchOptionsDirectionsModeDriving instead
    NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeWalking};
    // Get the "Current User Location" MKMapItem
    MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation];
    // Pass the current location and destination map items to the Maps app
    // Set the direction mode in the launchOptions dictionary
    [MKMapItem openMapsWithItems:@[currentLocationMapItem, mapItem] 
                    launchOptions:launchOptions];
}

Orijinal iOS 5 korumak ve *11 bundan sonra* else deyimindeki kod düşürebilirsiniz. Eğer openMapsWithItems: dizideki öğelerin sırasını tersine çevirirseniz, yön, koordinat alırsınız unutmayıniçinbulunduğunuz konumu. Muhtemelen MKMapItem geçerli konum yerine inşa göster öğesi geçerek herhangi iki yer arasında yol tarifi almak için kullanabilirsiniz. Bunu hiç denemedim.

Eğer yön vermek istediğiniz adresi (dize olarak) varsa son olarak, geocoder CLPlacemark Bu arada ** 14, bir oluşturmak için kullanın.

// Check for iOS 6
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:@"Piccadilly Circus, London, UK" 
        completionHandler:^(NSArray *placemarks, NSError *error) {

        // Convert the CLPlacemark to an MKPlacemark
        // Note: There's no error checking for a failed geocode
        CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0];
        MKPlacemark *placemark = [[MKPlacemark alloc]
                                  initWithCoordinate:geocodedPlacemark.location.coordinate
                                  addressDictionary:geocodedPlacemark.addressDictionary];

        // Create a map item for the geocoded address to pass to Maps app
        MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
        [mapItem setName:geocodedPlacemark.name];

        // Set the directions mode to "Driving"
        // Can use MKLaunchOptionsDirectionsModeWalking instead
        NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving};

        // Get the "Current User Location" MKMapItem
        MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation];

        // Pass the current location and destination map items to the Maps app
        // Set the direction mode in the launchOptions dictionary
        [MKMapItem openMapsWithItems:@[currentLocationMapItem, mapItem] launchOptions:launchOptions];

    }];
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • aki6336

    aki6336

    14 AĞUSTOS 2008
  • CZTUTORIALS

    CZTUTORIALS

    28 Ocak 2011
  • Tinkernut

    Tinkernut

    28 Aralık 2006