gpt4 book ai didi

ios - 苹果 map 上的方向

转载 作者:行者123 更新时间:2023-11-29 01:52:51 27 4
gpt4 key购买 nike

我们可以使用一组点在苹果 map 上获取方向吗?以下代码片段绘制的是直线而不是方向

- (IBAction)getRoute:(id)sender {


[self.mapView removeOverlay:self.routeLine];

CLLocationCoordinate2D overflowLotCoords[5]={
CLLocationCoordinate2DMake(39.04864351611461,-76.8513227245313),
CLLocationCoordinate2DMake(39.04851710015167,-76.8517540587399),

CLLocationCoordinate2DMake(39.04695987529381,-76.85235192135768),
CLLocationCoordinate2DMake(39.04734847050665,-76.85236298239703),
CLLocationCoordinate2DMake(39.04779491740192,-76.85232236959109)

};



MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:overflowLotCoords count:4];
[self.mapView addOverlay:polyLine];
self.routeLine = polyLine;

}

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithOverlay:overlay];
[renderer setStrokeColor:[UIColor redColor]];
[renderer setLineWidth:4.0];
[renderer setStrokeColor:[UIColor redColor]];
return renderer;
}
return nil;
}

我想使用一组点来绘制路线,我确实有源和目的地以及点列表。绘制路线后,我会使用网络服务获取当前位置,并希望在路线上显示位置。

enter image description here

最佳答案

您可以尝试这种方式并设置您的坐标:

 - (void)viewDidLoad {
[super viewDidLoad];

// center map
CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(47.081012, 2.398781);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 3000000, 3000000)];
[self.mapView setRegion:adjustedRegion animated:YES];

[self showLines];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

- (void)showLines {
CLLocationCoordinate2D *pointsCoordinate = (CLLocationCoordinate2D *)malloc(sizeof(CLLocationCoordinate2D) * 3);
pointsCoordinate[0] = CLLocationCoordinate2DMake(48.856614, 2.352221);
pointsCoordinate[1] = CLLocationCoordinate2DMake(45.764043, 4.835658);
pointsCoordinate[2] = CLLocationCoordinate2DMake(43.296482, 5.369779);


MKPolyline *polyline = [MKPolyline polylineWithCoordinates:pointsCoordinate count:3];
free(pointsCoordinate);

[self.mapView addOverlay:polyline];
}


- (MKPolylineRenderer *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay{

// create a polylineView using polyline overlay object
MKPolylineRenderer *polylineView = [[MKPolylineRenderer alloc] initWithPolyline:overlay];

// Custom polylineView
polylineView.strokeColor = [UIColor orangeColor];
polylineView.lineWidth = 2.0;
polylineView.alpha = 0.5;

return polylineView;
}

关于ios - 苹果 map 上的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31217256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com