2012-09-28 8 views
6

मैं आईओएस < 6 से एक ऐप अपडेट करना चाहता हूं जो Google मानचित्र का उपयोग करता है। मेरे ऐप में मानचित्र पर बहुत सारे पिन हैं, और, जब कोई उपयोगकर्ता उनमें से किसी एक पर टैप करता है, तो आईफोन अपने वर्तमान स्थान और मूल मानचित्र ऐप के साथ गंतव्य प्राप्त करने के लिए साझा एप्लिकेशन की तरह मानचित्र को कॉल करता है। आईओएस 6 के साथ, वही निर्देश (नीचे पोस्ट) स्पष्ट रूप से Google मानचित्र के बजाय सफारी खोलें। मैं एक आईफोन-चक्र लिखना चाहता हूं जो डिवाइस पर आईओएस स्थापित करता है: यदि < 6, आईओएस> 6 तो ..... (नया ऐप्पल नक्शा खोलें और वहां दिशा प्राप्त करें) कुछ भी नहीं बदला।मैं ए से बी से एक्सकोड में एक आईफोन आईओएस 6 ऐप पर दिशा कैसे प्राप्त कर सकता हूं?

कोई मेरी मदद कर सकता है?

यहाँ कार्रवाई आईओएस 6

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 

    [self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES]; 


    NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude]; 

    NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
    [[UIApplication sharedApplication] openURL:url]; 



} 

उत्तर

4

इससे पहले कि मैं इस एक नीचे पोस्ट की तरह एक पूर्वप्रक्रमक कोड का उपयोग किया है चक्र के लिए मेरी हालत को परिभाषित करने के।

#define SYSTEM_VERSION_LESS_THAN(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) 
फिर

:

if (SYSTEM_VERSION_LESS_THAN(@"6.0")) { 
     NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude]; 
     NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
     [[UIApplication sharedApplication] openURL:url]; 
    } 

else { 
     NSString* addr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude]; 
     NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
     [[UIApplication sharedApplication] openURL:url]; 


    } 

यह अलविदा काम करने के लिए लगता है!

+1

@Alessandro ब्रावा: thxs अपने कोड मुझे मदद की। मैं अब एक बात पूछना चाहता था .. मैं सीधे अपने ऐप पर कैसे जा सकता हूं। अब मैं मानचित्र के ऐप से मार्ग प्राप्त करने के बाद अपने ऐप पर वापस नहीं जा पाऊंगा। कृपया मदद करें .. धन्यवाद !! – nikesh

14

मैं आईओएस 6 में यूआरएल के माध्यम से मानचित्र ऐप खोलने के बजाय [एमके मैपआईटम ओपनमैप्सविथ इटम्स:] का उपयोग करने की सलाह देता हूं। यदि आप यूआरएल का उपयोग करते हैं, तो आप "वर्तमान स्थान" पास नहीं कर पाएंगे और बारी करने की क्षमता खो देंगे -बी-मोड़ नेविगेशन। MKMapItem के पास वर्तमान स्थान के लिए एक विशिष्ट आइटम है, जो पारित होने पर, मौजूदा स्थान का उपयोग कर मानचित्र को स्रोत पते के रूप में खोल देगा जिससे इस प्रकार बारी-बारी-बारी नेविगेशन सक्षम हो सके।

- (void)openMapsWithDirectionsTo:(CLLocationCoordinate2D)to { 
    Class itemClass = [MKMapItem class]; 
    if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { 
     MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation]; 
     MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[[MKPlacemark alloc] initWithCoordinate:to addressDictionary:nil] autorelease]]; 
     toLocation.name = @"Destination"; 
     [MKMapItem openMapsWithItems:[NSArray arrayWithObjects:currentLocation, toLocation, nil] 
         launchOptions:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber numberWithBool:YES], nil] 
                   forKeys:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeKey, MKLaunchOptionsShowsTrafficKey, nil]]]; 
     [toLocation release]; 
    } else { 
     NSMutableString *mapURL = [NSMutableString stringWithString:@"http://maps.google.com/maps?"]; 
     [mapURL appendFormat:@"saddr=Current Location"]; 
     [mapURL appendFormat:@"&daddr=%f,%f", to.latitude, to.longitude]; 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[mapURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; 
    } 
} 
+0

हाय, मैंने कोशिश की। लेकिन सेब के मानचित्र में यह "चेतावनी उपलब्ध नहीं है" जैसे अलर्ट प्राप्त कर रहा है। क्यूं कर? – Dev

+0

आप स्रोत और गंतव्य पते क्या हैं? क्या आप मानचित्र ऐप में उन बिंदुओं के बीच दिशानिर्देश प्राप्त कर सकते हैं?यह संभव है कि उन दो बिंदुओं के बीच कोई रूटिंग जानकारी न हो। – bromanko

+0

मेरा स्रोत कुवैत है और गंतव्य पता ओमान है। Google नक्शे में Iam इन दोनों के बीच दिशा प्राप्त कर रहा है। लेकिन मानचित्र ऐप में नहीं मिल रहा है और यह कह रहा है "दिशाएं उपलब्ध नहीं हैं"। क्या आप कुछ पता सुझा सकते हैं जिसके लिए मैं दिशा प्राप्त कर सकता हूं। – Dev

1

स्वीकृत उत्तर मेरे लिए काम नहीं करता था। वर्तमान स्थान को सही भाषा में होना चाहिए और ios6 संस्करण भी सही ढंग से लोड नहीं हुआ है। मेरे लिए निम्नलिखित काम किया।

NSString *destinationAddress = @"Amsterdam"; 

Class itemClass = [MKMapItem class]; 
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { 

    CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
    [geocoder geocodeAddressString:destinationAddress completionHandler:^(NSArray *placemarks, NSError *error) { 
     if([placemarks count] > 0) { 

      MKPlacemark *placeMark = [[MKPlacemark alloc] initWithPlacemark:[placemarks objectAtIndex:0]]; 

      MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:placeMark]; 

      MKMapItem *mapItem2 = [MKMapItem mapItemForCurrentLocation]; 


      NSArray *mapItems = @[mapItem, mapItem2]; 

      NSDictionary *options = @{ 
     MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, 
     MKLaunchOptionsMapTypeKey: 
      [NSNumber numberWithInteger:MKMapTypeStandard], 
     MKLaunchOptionsShowsTrafficKey:@YES 
      }; 

      [MKMapItem openMapsWithItems:mapItems launchOptions:options]; 

     } else { 
      //error nothing found 
     } 
    }]; 
    return; 
} else { 

    NSString *sourceAddress = [LocalizedCurrentLocation currentLocationStringForCurrentLanguage]; 

    NSString *urlToOpen = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%@&daddr=%@", 
       [sourceAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], 
       [destinationAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlToOpen]]; 
} 

iOS5 के लिए मैं iOS6 के लिए इस पोस्ट http://www.martip.net/blog/localized-current-location-string-for-iphone-apps

से LocalizedCurrentLocation का उपयोग मैं CLGeocoder का उपयोग स्थान-चिह्न और फिर इसके साथ नक्शा और वर्तमान स्थान को खोलने के लिए।

CoreLocation.framework और MapKit.framework

1

स्विफ्ट 2.0 संगत जोड़ने का ध्यान रखें।

मुझे अभी तक कोई संपूर्ण जवाब नहीं मिला है।

/** 
Try to open google maps with navigation feature and with given coordinates 

- parameter latitude:  destination latitude 
- parameter longitude:  destination longitude 
- parameter destinationName: destination name 
- parameter completion:  completion callback 
*/ 
static func openGoogleMapsNavigation(latitude: Double, longitude: Double, destinationName: String, completion: ((error: NSError?) -> (Void))?) { 
    let directionRequest: MKDirectionsRequest = MKDirectionsRequest() 
    let destination = Utils.createMapItem(name: destinationName, latitude: latitude, longitude: longitude) 
    directionRequest.source = MKMapItem.mapItemForCurrentLocation() 
    directionRequest.destination = destination 
    directionRequest.transportType = MKDirectionsTransportType.Automobile 
    directionRequest.requestsAlternateRoutes = true 
    let directions: MKDirections = MKDirections(request: directionRequest) 
    directions.calculateDirectionsWithCompletionHandler { (response: MKDirectionsResponse?, error: NSError?) -> Void in 
     if error == nil { 
      destination.openInMapsWithLaunchOptions([ MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]) 
     } 
     completion?(error: error) 
    } 
} 

मैं कहाँ इस उपयोगिता विधि है:

static func createMapItem(name name: String, latitude: Double, longitude: Double) -> MKMapItem { 
    let coordinates = CLLocationCoordinate2DMake(latitude, longitude) 
    let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil) 
    let mapItem = MKMapItem(placemark: placemark) 
    mapItem.name = name 
    return mapItem 
} 
0

तेज में एक जवाब के लिए खोज रहे लोगों के लिए -

//MARK:- ViewDidLoad 
     let directionRequest = MKDirectionsRequest() 
        directionRequest.source = self.sourceMapitem 
        directionRequest.destination = self.destinationMapitem 
        directionRequest.transportType = .Automobile 
       // where sourceMapitem and destinationMapitem are MKMapItem  
        let directions = MKDirections(request: directionRequest) 
        directions.calculateDirectionsWithCompletionHandler { 
         (response, error) -> Void in 
        if response != nil { 
         let route = response!.routes[0] 
         self.myMapView.addOverlay((route.polyline), level: MKOverlayLevel.AboveRoads) 
         print("OVER") 
        } 
         else{ 
          print(" ERROR: \(error)") 
         } 
        } 
     //MARK:- DefineFunctions 
     func showRoute(response: MKDirectionsResponse) { 

       for route in response.routes { 

        myMapView.addOverlay(route.polyline, 
             level: MKOverlayLevel.AboveRoads) 
       } 
      } 
संबंधित मुद्दे

 संबंधित मुद्दे