ios - Draw more than one group of lines in MKMapView using MKPolyline -
i'm using code draw 1 grouping of lines:
cllocationcoordinate2d points[[routes count]]; for(int = 0; < self.routes.count; i++) { cllocation* location = [self.routes objectatindex:i]; points[i] = cllocationcoordinate2dmake(location.coordinate.latitude, location.coordinate .longitude); } self.routeline = [mkpolyline polylinewithcoordinates: points count: [routes count]]; [self.mapview setvisiblemaprect: [self.routeline boundingmaprect] animated: yes]; [self.mapview addoverlay:self.routeline];
and it's working 1 grouping of lines comes nsarray *routes
, need more 1 grouping of lines, illustration nsmutablearray *routes = { nsarray routes , nsarray other grouping first illustration , array }
this:
int sumacount = [a1 count] + [a2 count] + [a3 count]; cllocationcoordinate2d puntitos[sumacount]; int c = 0; (nsarray *array in rutas) { (cllocation *cada in array) { puntitos[c] = cllocationcoordinate2dmake(cada.coordinate.latitude, cada.coordinate.longitude); c++; } self.routeline = [mkpolyline polylinewithcoordinates: puntitos count: sumacount]; [self.mapview addoverlay: self.routeline]; }
but exception:
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '*** -[nsregularexpression enumeratematchesinstring:options:range:usingblock:]: nil argument'
there 2 issues: bugs in supplied code , exception.
code bugs
you adding overlay sumacount
points before finishing building of puntitos
construction (e.g. first time addoverlay
called, have added [a1 count]
points). you're assuming a1
, a2
, , a3
of items in rutas
. if want them connected, should:
addoverlay
out of loop; and don't utilize a1
, a2
, , a3
, rather iterated through rutas
sumacount
thus, if wanted bring together 3 groups of lines together, would:
int sumacount = 0; (nsarray *array in rutas) sumacount += [array count]; cllocationcoordinate2d puntitos[sumacount]; int c = 0; (nsarray *array in rutas) { (cllocation *cada in array) { puntitos[c] = cllocationcoordinate2dmake(cada.coordinate.latitude, cada.coordinate.longitude); c++; } } self.routeline = [mkpolyline polylinewithcoordinates: puntitos count: sumacount]; [self.mapview addoverlay: self.routeline];
if you're dealing 3 separate groups of lines, should:
for (nsarray *array in rutas) { int sumacount = [array count]; cllocationcoordinate2d puntitos[sumacount]; int c = 0; (cllocation *cada in array) { puntitos[c] = cllocationcoordinate2dmake(cada.coordinate.latitude, cada.coordinate.longitude); c++; } mkpolyline routeline = [mkpolyline polylinewithcoordinates: puntitos count: c]; [self.mapview addoverlay: routeline]; }
note in latter example, i'm not using mkpolyline
property, local var. if need maintain array of these mkpolyline
objects, go ahead , that, purposes of above code, don't need it. frankly, in first example, i'd inclined local mkpolyline
variable, too. why maintain in class property?!?
exception
the above fixes bugs in listed code, exception points yet issue. code (since first effort create mkpolyline
using sumacount
points have set few of them). problem may reset elsewhere, too, because exception not expect code's bugs. doing regular look matching elsewhere in code? if you're convinced issue in code, itself, can
nslog(@"rutas=%@", rutas);
personally, i'd surprised if regex problem caused this, code in original question cause unexpected problems. i'd prepare code, , see if exception still occurs. if does, add together rutas
log statement, better, search nsregularexpression
in project , see might using that. can turn on exception breakpoints (just turn on exceptions).
ios objective-c mkmapview mapkit polyline
No comments:
Post a Comment