gpt4 book ai didi

ios - 如何在 iOS 中通过 map-kit 在两点之间绘制折线?

转载 作者:行者123 更新时间:2023-11-28 21:37:25 25 4
gpt4 key购买 nike

我有两点然后如何绘制折线但折线不来我在

中这样声明

.m文件

     - (void)viewDidLoad {
[super viewDidLoad];

double currentLatitude = [[NSUserDefaults standardUserDefaults] doubleForKey:@"currentLatitude"];

double currentLongitude = [[NSUserDefaults standardUserDefaults] doubleForKey:@"currentLatitude"];

double shopLatitude = [[NSUserDefaults standardUserDefaults] doubleForKey:@"shopLatitude"];
double shopLongitude = [[NSUserDefaults standardUserDefaults] doubleForKey:@"shopLongitude"];

CLLocationCoordinate2D coordinateArray[2];
coordinateArray[0] = CLLocation Coordinate 2D Make(currentLatitude, currentLongitude);

coordinateArray[1] = CLLocation Coordinate 2D Make(shopLatitude,shopLongitude);



self.routeLine = [MK Poly line poly lineWithCoordinates:coordinateArray count:2];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]];
[self.mapView addOverlay:self.routeLine];

}

我们将不胜感激。

最佳答案

1) 添加MKMapViewDelegate

#import <MapKit/MapKit.h>

@interface YourViewController : UIViewController <MKMapViewDelegate>

2) 设置委托(delegate)

self.mapView.delegate = self;

3) 实现viewForOverlay

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.strokeColor = [UIColor redColor];
polylineView.lineWidth = 1.0;
return polylineView;
}

关于ios - 如何在 iOS 中通过 map-kit 在两点之间绘制折线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33364565/

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