gpt4 book ai didi

ios - 如何在 map 上的两点之间绘制箭头? map 套件

转载 作者:行者123 更新时间:2023-11-29 10:56:57 26 4
gpt4 key购买 nike

如何在 map 上的两点之间画一个箭头?
我尝试计算纬度和经度,但出了点问题。

最好的问候,麦克斯

这是我的代码和结果图

        int currpoints1 = 2;
NSLog(@"!!!!!!!!%d ",numPoints);
while(currpoints1 < numPoints)
{

TrackPoint* current = nil;
CLLocationCoordinate2D* coordsArrrow = malloc((3) * sizeof(CLLocationCoordinate2D));
for (int i =currpoints1, j=0; i < numPoints; i=i+1, j++)
{
current = [cashpoints objectAtIndex:i];
coordsArrrow[j] = current.coordinate;
if (i % 2 !=0) {
int Gug = 30;

int ug;
float bx, by, ex, ey;
bx = coordsArrrow[0].latitude;by = coordsArrrow[0].longitude;
ex = coordsArrrow[1].latitude;ey = coordsArrrow[1].longitude;
float Lstr = sqrt((ex-ey)*(ex-ey)+(bx-by)*(bx-by));
ug = [self RetGradW:(abs(coordsArrrow[1].latitude-coordsArrrow[0].latitude)) height:abs(coordsArrrow[1].longitude-coordsArrrow[0].longitude)];
ug = ug - Gug;
coordsArrrow[0].latitude = ex;
coordsArrrow[0].longitude = ey;
coordsArrrow[1].latitude = ex+Lstr*cos(ug*M_PI/180);
coordsArrrow[1].longitude = ey+Lstr*sin(ug*M_PI/180);
ug=ug+2*Gug;
coordsArrrow[2].latitude = ex+Lstr*cos(ug*M_PI/180);
coordsArrrow[2].longitude = ey+Lstr*sin(ug*M_PI/180);

MKPolyline *points = [MKPolyline polylineWithCoordinates:coordsArrrow count:3];
points.subtitle = @"arrow";
[map addOverlay:points];
break;
}
}
free(coordsArrrow);
currpoints1 = currpoints1 +14;
}

enter image description here

最佳答案

伙计们。我换个方式。在两点之间进行标注和方向旋转。

方法:

计算方向:

     int currpoints1 = 2;
NSLog(@"!!!!!!!!%d ",numPoints);
while(currpoints1 < numPoints)
{

TrackPoint* current = nil;
CLLocationCoordinate2D* coordsArrrow = malloc((2) * sizeof(CLLocationCoordinate2D));
for (int i =currpoints1, j=0; i < numPoints; i=i+1, j++)
{
current = [cashpoints objectAtIndex:i];
coordsArrrow[j] = current.coordinate;
if (i % 2 !=0) {
DirectAnnotation *placemark=[[DirectAnnotation alloc] initWithCoordinate: coordsArrrow[0]];

CLLocationCoordinate2D coord1 = coordsArrrow[0];
CLLocationCoordinate2D coord2 = coordsArrrow[1];

CLLocationDegrees deltaLong = coord2.longitude - coord1.longitude;
CLLocationDegrees yComponent = sin(deltaLong) * cos(coord2.latitude);
CLLocationDegrees xComponent = (cos(coord1.latitude) * sin(coord2.latitude)) - (sin(coord1.latitude) * cos(coord2.latitude) * cos(deltaLong));

CLLocationDegrees radians = atan2(yComponent, xComponent);
CLLocationDegrees degrees = radiansToDegrees(radians) + 360;

self.dir = fmod(degrees, 360);


NSLog(@"%f,%f %f,%f",coordsArrrow[0].latitude,coordsArrrow[0].longitude,coordsArrrow[1].latitude,coordsArrrow[1].longitude);
[self.map addAnnotation:placemark];
break;
}
}
free(coordsArrrow);
currpoints1 = currpoints1 +14;
}

注解:

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


if ([annotation isKindOfClass:[DirectAnnotation class]]) {
arrow=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"parkingloc"];
arrow.image = [UIImage imageNamed:@"userLocationCompass.png"];


CGAffineTransform transform = CGAffineTransformMakeRotation(degreesToRadians(dir));
arrow.transform = transform;

return arrow;
}else {
return nil;
}}

但是我有一些问题
缩放前: enter image description here

缩放后: enter image description here

方向困惑。

关于ios - 如何在 map 上的两点之间绘制箭头? map 套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17829611/

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