ios - how to draw an arrow between two points on the map? MapKit -
how draw arrow between 2 points on map?
try calc latitude , longitude, goes wrong.
best regards, max
this code , result picture
int currpoints1 = 2; nslog(@"!!!!!!!!%d ",numpoints); while(currpoints1 < numpoints) { trackpoint* current = nil; cllocationcoordinate2d* coordsarrrow = malloc((3) * sizeof(cllocationcoordinate2d)); (int =currpoints1, j=0; < 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; }
oh guys. change other way. make annotation , rotate direction between 2 point.
metods :
calc direction:
int currpoints1 = 2; nslog(@"!!!!!!!!%d ",numpoints); while(currpoints1 < numpoints) { trackpoint* current = nil; cllocationcoordinate2d* coordsarrrow = malloc((2) * sizeof(cllocationcoordinate2d)); (int =currpoints1, j=0; < 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; }
and
annotation:
- (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; }}
but have problem
before zoom:
after zoom :
direction confused.
Comments
Post a Comment