-1

現在の場所からfloat値である目的の座標に線を引くことができる機能をアプリで作成したいと思います。同じことをするための最も効率的な方法を教えてください。

4

1 に答える 1

0

私はすべてのiOSについて私の質問の答えを持っています、そしてそれは次のとおりです

//ジオコーダーを使用して方向を表示するには... * -(void)showDirection:(id)sender

{
    NSString *deviceVersion   = [[UIDevice currentDevice] systemVersion];
    NSLog(@"My Device version is :%@ ",deviceVersion);


    //*********  For ios 6 supporting devices  *********
    if ([deviceVersion isEqualToString:@"6.0"])
    {

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

            CLGeocoder *geocoder = [[CLGeocoder alloc] init];
            CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:getLatitude
                                                                longitude:getLongitude];

            [geocoder reverseGeocodeLocation:newLocation
                           completionHandler:^(NSArray *placemarks, NSError *error) {

                               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
        {
            UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to Get Your Location"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [errorAlert show];

        }
    }
    //*********  For other ios supporting devices  *********
    else {

        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
        region.center.latitude = getLatitude;
        region.center.longitude = getLongitude;

        MKCoordinateRegion currentRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };
        currentRegion.center.latitude = currentLatitude;
        currentRegion.center.longitude = currentLongitude;

        region.span.longitudeDelta = 4.0f;
        region.span.latitudeDelta = 4.0f;
        currentRegion.span.longitudeDelta = 4.0f;
        currentRegion.span.latitudeDelta = 4.0f;

        CLLocationCoordinate2D start = { currentRegion.center.latitude, currentRegion.center.longitude };
        CLLocationCoordinate2D destination = { region.center.latitude, region.center.longitude };

        NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",start.latitude, start.longitude, destination.latitude, destination.longitude];

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];

    }

}
于 2013-01-04T09:43:12.577 に答える