3

我想找到一种简单的方法来获取方向。有什么办法可以做到这一点mapview吗?以下是我当前的代码。

- (IBAction)goToMap:(id)sender {

[self.view addSubview:self.mapUIView];
[self.mapUIView setFrame:CGRectMake(0, 0, 320, 460)];

self.mapview.mapType = MKMapTypeStandard;

CLLocationCoordinate2D coordinate;
coordinate.latitude = [[self.find lat] floatValue];
coordinate.longitude = [[self.find lng] floatValue];
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];

[annotation setCoordinate:coordinate];
[annotation setTitle:[self.find name]];
//[annotation setSubtitle:@"Hello"];
[self.mapview addAnnotation:annotation];
[annotation release];

[self zoomMapViewToFitAnnotations:self.mapview animated:YES];

 }
4

4 回答 4

0

如果你想显示设备的当前位置(比如开车时),你必须在你的项目中添加 CoreLocation 框架,并且应该使用“updateLocation”方法来获取当前位置,但是如果你想在两个位置之间绘制一条路径,你必须使用谷歌API为此。

于 2012-10-22T12:30:13.633 回答
0

您不能将 MapKit 用于行车路线。它不支持这一点。

于 2012-10-22T12:16:13.283 回答
0
CLLocationManager *manager = [[CLLocationManager alloc] init] ;
    CLLocationCoordinate2D currentLocation = [manager location].coordinate;
    CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(37.365502,-94.394531);
    NSString *fromLocation = [NSString stringWithFormat: @"%f,%f",
                      currentLocation.latitude, currentLocation.longitude];
    NSString *toLocation = [NSString stringWithFormat: @"%f,%f",
                                Coordinate.latitude, Coordinate.longitude];
    NSString *url = [NSString stringWithFormat:
                     @"http://maps.google.com/maps?saddr=%@&daddr=%@", fromLocation, fromLocation];

    UIWebView *webView = [[UIWebView alloc]init];
    NSURL *targetURL = [NSURL URLWithString:url];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [webView loadRequest:request];
于 2013-04-19T13:10:02.507 回答
0

如果您想绘制方向,请使用: https ://github.com/kishikawakatsumi/MapKit-Route-Directions

于 2012-10-22T12:51:33.653 回答