【问题标题】:Plotting a route between user's location and specified location on Google MapKit in Xcode在 Xcode 中的 Google MapKit 上绘制用户位置和指定位置之间的路线
【发布时间】:2011-03-23 15:16:05
【问题描述】:

嘿,伙计, 在我的 iPhone 项目中,我使用 MapKit 构建了一个谷歌地图,并在地图上指定了我公司的位置。现在我想添加一个小功能,我的谷歌地图将绘制一条从用户位置到我公司位置的路线。到目前为止,这是我用来指定公司位置的代码

#import "GoogleMap.h"
#import "MyAnnotation.h"

@implementation GoogleMap

    - (void)viewDidLoad {
    [super viewDidLoad];

    variable1 = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] 
                                                         pathForResource:@"NewYorkAreas" 
                                                         ofType:@"plist"]];

    double minLat = [[variable1 valueForKeyPath:@"@min.latitude"] doubleValue];
    double maxLat = [[variable1 valueForKeyPath:@"@max.latitude"] doubleValue];
    double minLon = [[variable1 valueForKeyPath:@"@min.longitude"] doubleValue];
    double maxLon = [[variable1 valueForKeyPath:@"@max.longitude"] doubleValue];

    MKCoordinateRegion region;
    region.center.latitude = (maxLat + minLat) / 2.0;
    region.center.longitude = (maxLon + minLon) / 2.0;
    region.span.latitudeDelta = (maxLat - minLat) * 1.05;
    region.span.longitudeDelta = (maxLon - minLon) * 1.05;
    map.region = region;

    for (NSDictionary *newYorkAreasDict in variable1){
        MyAnnotation *annotation = [[MyAnnotation alloc] initWithDictionary:newYorkAreasDict];
        [map addAnnotation:annotation];
        [annotation release];
    }
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{

    if (map.userLocation == annotation){
        return nil;
    }

    NSString *identifier = @"MY_IDENTIFIER";

    MKAnnotationView *annotationView = [map dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (annotationView == nil){
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation 
                                                       reuseIdentifier:identifier] 
                          autorelease];
        annotationView.image = [UIImage imageNamed:@"logo.png"];
        annotationView.canShowCallout = YES;

        annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    }
    return annotationView;
}

所以现在,我想实现用户的位置,并在用户的位置和我的公司之间绘制一条路线,但我不知道如何编码,所以希望有人能帮助我,谢谢!

【问题讨论】:

    标签: iphone objective-c xcode google-maps mapkit


    【解决方案1】:

    一种方法是您需要获取路线的 GPS 坐标,然后您可以使用 MKOverlayView。

    查看this 了解更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多