在印度驾驶路线ios7

时间:2014-07-14 09:56:09

标签: ios7

我需要在iOS 7中显示行车路线。我知道我们可以使用MKDirections来达到此目的,但问题是Apple Maps不会在印度显示行车路线。当我用谷歌搜索我发现如果谷歌地图安装在iPhone设备上我们可以使用它显示方向,否则我们无法显示 方向。我们可以在iOS中使用Google地图吗? Apple是否允许在iOS 7中使用谷歌地图。

以下是我使用的代码:

MKPlacemark *source = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(37.776142, -122.424774)
    addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ];
// MKPlacemark *source = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(10.00145, 76.2828)
    addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ];

MKMapItem *srcMapItem = [[MKMapItem alloc]initWithPlacemark:source];
[srcMapItem setName:@""];

MKPlacemark *destination = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(37.73787, -122.373962)
    addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ];
//  MKPlacemark *destination = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(9.950012, 76.349988)
    addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ];

MKMapItem *distMapItem = [[MKMapItem alloc]initWithPlacemark:destination];
[distMapItem setName:@""];

MKDirectionsRequest *request = [[MKDirectionsRequest alloc]init];
[request setSource:srcMapItem];
[request setDestination:distMapItem];
[request setTransportType:MKDirectionsTransportTypeWalking];

MKDirections *direction = [[MKDirections alloc]initWithRequest:request];

[direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {

    NSLog(@"response = %@",response);
    NSArray *arrRoutes = [response routes];
    [arrRoutes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

        MKRoute *rout = obj;

        MKPolyline *line = [rout polyline];
        [self.mkMapView addOverlay:line];
        NSLog(@"Rout Name : %@",rout.name);
        NSLog(@"Total Distance (in Meters) :%f",rout.distance);

        NSArray *steps = [rout steps];

        //NSLog(@"Total Steps : %d",[steps count]);

        [steps enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            NSLog(@"Rout Instruction : %@",[obj instructions]);
            NSLog(@"Rout Distance : %f",[obj distance]);
        }];
    }];
}];

1 个答案:

答案 0 :(得分:0)

您可以使用谷歌地图轻松拍摄webview并解析下面给出的字符串

NSString *urlAddress = @"http://maps.google.co.in/maps?hl=en&tab=wl";

NSURL *url = [NSURL URLWithString:urlAddress];

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[webView loadRequest:requestObj];
self.mapView.showsUserLocation = YES;

self.locationController = [[CoreLocationController alloc] init];
self.locationController.delegate = self;
[self.locationController.locationManager startUpdatingLocation];

// Do any additional setup after loading the view.

- (void)update:(CLLocation *)location {
    self.lblLatitude.text= [NSString stringWithFormat:@"Latitude  %f", [location coordinate].latitude];
    self.lblLongitude.text = [NSString stringWithFormat:@"Longitude  %f", [location coordinate].longitude];
}

- (void)locationError:(NSError *)error {
    self.lblLatitude.text = [error description];
    self.lblLongitude.text = nil;
}