para over apple app ios iphone objective-c maps apple-maps

over - Abre la aplicación Apple Maps de la aplicación iOS con indicaciones



apple maps web (3)

Aquí está el código de trabajo para mostrar las instrucciones en el mapa de Apple. Funcionará para el lugar actual a su lugar de destino y solo necesita pasar el lugar de destino más largo y más largo.

double destinationLatitude, destinationLongitude; destinationLatitude=// Latitude of destination place. destinationLongitude=// Longitude of destination place. Class mapItemClass = [MKMapItem class]; if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { // Create an MKMapItem to pass to the Maps app CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(destinationLatitude,destinationLongitude); MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]; MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark]; [mapItem setName:@"Name/text on destination annotation pin"]; // Set the directions mode to "Driving" // Can use MKLaunchOptionsDirectionsModeDriving 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]; }

También, compartanme aquí, si notan algún problema o necesitamos encontrar otra manera de hacerlo.

Como indica el título, me gustaría abrir la aplicación de mapas nativos en el dispositivo iOS desde mi propia aplicación, presionando un botón. Actualmente, he usado un MKmapview que muestra un pin simple con lat / long tomado de un archivo json .

El código es este:

- (void)viewDidLoad { [super viewDidLoad]; } // We are delegate for map view self.mapView.delegate = self; // Set title self.title = self.location.title; // set texts... self.placeLabel.text = self.location.place; self.telephoneLabel.text = self.location.telephone; self.urlLabel.text = self.location.url; **// Make a map annotation for a pin from the longitude/latitude points MapAnnotation *mapPoint = [[MapAnnotation alloc] init]; mapPoint.coordinate = CLLocationCoordinate2DMake([self.location.latitude doubleValue], [self.location.longitude doubleValue]); mapPoint.title = self.location.title;** // Add it to the map view [self.mapView addAnnotation:mapPoint]; // Zoom to a region around the pin MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(mapPoint.coordinate, 500, 500); [self.mapView setRegion:region];

} `

Cuando tocas el pin, aparece un cuadro de información con un título y un botón de información.

este es el codigo

#pragma mark - MKMapViewDelegate - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { MKPinAnnotationView *view = nil; static NSString *reuseIdentifier = @"MapAnnotation"; // Return a MKPinAnnotationView with a simple accessory button view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier]; if(!view) { view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; view.canShowCallout = YES; view.animatesDrop = YES; } return view; }

Quiero hacer un método que abra la aplicación de mapas con indicaciones desde la ubicación de los usuarios actuales al mapa de puntos anterior, al hacer clic en el botón en el cuadro de información de arriba. ¿Es eso posible? También ¿Puedo personalizar el aspecto de este botón? (Me refiero a colocar una imagen diferente en el botón para que se vea como "presione un poco hacia la dirección").

Lo siento si esta es una pregunta estúpida, pero esta es mi primera aplicación de iOS y Obj-c es un lenguaje totalmente nuevo para mí.

Gracias por todas las respuestas por adelantado.


Inicia un botón y agrega acción al botón:

Código Objective-C

NSString* directionsURL = [NSString stringWithFormat:@"http://maps.apple.com/?saddr=%f,%f&daddr=%f,%f",self.mapView.userLocation.coordinate.latitude, self.mapView.userLocation.coordinate.longitude, mapPoint.coordinate.latitude, mapPoint.coordinate.longitude]; if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString: directionsURL] options:@{} completionHandler:^(BOOL success) {}]; } else { [[UIApplication sharedApplication] openURL:[NSURL URLWithString: directionsURL]]; }

con el mapPoint es hacia donde quieres dirigirte.

Swift3 o posterior

let directionsURL = "http://maps.apple.com/?saddr=35.6813023,139.7640529&daddr=35.4657901,139.6201192" guard let url = URL(string: directionsURL) else { return } if #available(iOS 10.0, *) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url) }

Tenga en cuenta que saddr , daddr puede ser el nombre de la ubicación o la coordenada de la ubicación. Así, directionsURL puede ser:

// directions with location coordinate "http://maps.apple.com/?saddr=35.6813023,139.7640529&daddr=35.4657901,139.6201192" // or directions with location name "http://maps.apple.com/?saddr=Tokyo&daddr=Yokohama" // or directions from current location to destination location "http://maps.apple.com/?saddr=Current%20Location&daddr=Yokohama"

Más parámetros de opciones (como tipo de transporte, tipo de mapa ...) mira developer.apple.com/library/ios/featuredarticles/…


Puede abrir mapas con dirección usando este código: (asumiendo que su clase <MKAnnotation> de identificación tiene una propiedad pública CLLocationCoordinate2D llamada "coordenada")

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:[annotation coordinate] addressDictionary:nil]; MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark]; [mapItem setName:"WhereIWantToGo"]]; NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving}; [mapItem openInMapsWithLaunchOptions:options];

También puede cambiar el botón, en realidad está usando un botón de estilo estándar:

[UIButton buttonWithType:UIButtonTypeDetailDisclosure];

Pero puede asignar su botón personalizado con una imagen o una etiqueta:

[[UIButton alloc] initWithImage:[UIImage imageNamed:"directionIcon.png"]];