0

住所を取得し、それらを文字列として作成し、ジオコーディングを使用してそれぞれの座標 (緯度と経度) を取得し、到着予定時刻と到着予定距離を計算し、特定の半径内でユーザーに通知する必要があります。私はこのコードを使用していますが、機能しておらず、両方で 0.00000 しか得られません。助けていただければ幸いです。ありがとう

MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];


MKPlacemark *placemark3 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(coordination.latitude,coordination.longitude) addressDictionary:nil];
    MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark3];


    // source and destination are the relevant MKMapItem's
    MKPlacemark *placemark2 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(currentLocation.coordinate.latitude, currentLocation.coordinate.longitude) addressDictionary:nil];

    MKMapItem *source = [[MKMapItem alloc] initWithPlacemark:placemark2];
    request.source = source; // MKMapItem
    request.destination = destination;
    // Specify the transportation type
    request.transportType = MKDirectionsTransportTypeAutomobile;
    // If you're open to getting more than one route, requestsAlternateRoutes = YES; else requestsAlternateRoutes = NO;
    request.requestsAlternateRoutes = NO;
    MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
    [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {

        if (!error) {
            self.directionsResponse = response;
        }
    }];

    MKRoute *route = self.directionsResponse.routes[0];
    CLLocationDistance distance = route.distance; //distance in meter
    self.arrivalDistance.text =[NSString stringWithFormat:@"Distance to arrive in meters:\"%f\"",distance];
    NSTimeInterval seconds = route.expectedTravelTime; //ETA in Seconds
    self.arrivalTime.text=[NSString stringWithFormat:@"Minutes to arrive:\"%f\"", (seconds/60)];
4

0 に答える 0