2013-09-02 23 views
7

ETA'yı (tahmini varış zamanı), bulunduğum konumdan şu anki konumuma, geçerli konumuma doğru yolun ne olduğunu bilmek ister misiniz? Durum:Geçerli konumuma, herhangi bir konumdan ETA (tahmini varış zamanı) almanın uygun yolu nedir?

a. ex. - Başka bir cihazdan aldım (lon/lat) ve diğer kişinin beni ne zaman alacağını öğrenmek istiyorum ... Bu durumda kullanıcı için bu bilgiyi almak için hangi web servisini kullanabilirim? mapkit bu tür bir seçenek sunuyor mu?

b. Sunucu tarafında yapılacak ve kullanıcı konumumu gönderecek olursam, sunucu tarafındaki programlamamın ETA bilgilerini almak için kullanabileceği araçlar nelerdir?

Hepinize şimdiden teşekkür ederiz. Ben (benim anlayışına), başka yerlerde bulduğumuz gibi, sorunu google api şimdi her iOS kullanıcısına yüklü değil Google Haritalar uygulamasının kullanımını gerektirir olmasıdır - Is there any way to determine the driving time between two locations using Apple's Maps API? :

bunu gördüm.

+1

kodunu değiştirerek edildi için M route.distance kullanarak benim için çalıştı nasıl kullanılacağına dair snippet'idir IOS 7'deki bazı yeni SDK API'lerine bakmalısınız. – mattyohe

cevap

17

Bu yazı biraz eski olduğunu biliyorum ama iOS 7 Apple tüm bu bilgileri hesaplamak için MapKit bir API sağlamak beri durumda birileri cevap bakıyor. İşte

bu API

MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init]; 
    [request setSource:[MKMapItem mapItemForCurrentLocation]]; 
    [request setDestination:destination]; 
    [request setTransportType:MKDirectionsTransportTypeAutomobile]; 
    [request setRequestsAlternateRoutes:NO]; 
    MKDirections *directions = [[MKDirections alloc] initWithRequest:request]; 
    [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) { 
     if (! error && [response routes] > 0) { 
      MKRoute *route = [[response routes] objectAtIndex:0]; 
      //route.distance = The distance 
      //route.expectedTravelTime = The ETA 
     } 
    }]; 
+0

, bu yöntemde herhangi bir uzun süre için 0,00 döndürdüğüm işe yaradı ... Sizce bu konuda size yardımcı olabilir miyim? – Rohit

+0

Her zaman 'objectAtIndex: 0' yerine' firstObject' kullanın. Çarpmaya dayanıklı ve daha net – Laszlo

+0

Teşekkür ederim adamım. Ve sonucu biçimlendirmek için başka bir işlev kullanıyorum. –

5

Bu K'nın cevap ben bu yazının map directions tutorial

(IBAction)routeButtonPressed:(UIBarButtonItem *)sender { 
    MKDirectionsRequest *directionsRequest = [[MKDirectionsRequest alloc] init]; 
    MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:thePlacemark]; 
    [directionsRequest setSource:[MKMapItem mapItemForCurrentLocation]]; 
    [directionsRequest setDestination:[[MKMapItem alloc] initWithPlacemark:placemark]]; 
    directionsRequest.transportType = MKDirectionsTransportTypeAutomobile; 
    MKDirections *directions = [[MKDirections alloc] initWithRequest:directionsRequest]; 
    [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) { 
     if (error) { 
      NSLog(@"Error %@", error.description); 
     } else { 
      routeDetails = response.routes.lastObject; 
      [self.mapView addOverlay:routeDetails.polyline]; 
      self.destinationLabel.text = [placemark.addressDictionary objectForKey:@"Street"]; 
      self.distanceLabel.text = [NSString stringWithFormat:@"%0.1f Miles", routeDetails.distance/1609.344]; 

      self.etaLabel.text = [NSString stringWithFormat:@"%0.1f minutes",routeDetails.expectedTravelTime/60]; 

      //self.transportLabel.text = [NSString stringWithFormat:@"%u" ,routeDetails.transportType]; 
      self.allSteps = @""; 
      for (int i = 0; i < routeDetails.steps.count; i++) { 
       MKRouteStep *step = [routeDetails.steps objectAtIndex:i]; 
       NSString *newStep = step.instructions; 
       self.allSteps = [self.allSteps stringByAppendingString:newStep]; 
       self.allSteps = [self.allSteps stringByAppendingString:@"\n\n"]; 
       self.steps.text = self.allSteps; 


      } 
     } 

    }]; 
} 
+0

Bu işe yaradı mı? sen yardım – Rohit

İlgili konular