iphone - Drawing a line between the coordinates in MKMapView -


i want draw lines between coordinates in mkmapview..here code

aroute=[nsarray arraywithobjects:[[cllocation alloc] initwithlatitude:40.445418 longitude:-79.942714],[[cllocation alloc] initwithlatitude:40.444469 longitude:-79.948628],[[cllocation alloc] initwithlatitude:40.44569 longitude:-79.950388],[[cllocation alloc] initwithlatitude:40.446967 longitude:-79.95053],[[cllocation alloc] initwithlatitude:40.448874 longitude:-79.951715],[[cllocation alloc] initwithlatitude:40.45134 longitude:-79.953175],[[cllocation alloc] initwithlatitude:40.452213 longitude:-79.950895],[[cllocation alloc] initwithlatitude:40.452564 longitude:-79.949838],[[cllocation alloc] initwithlatitude:40.453528 longitude:-79.94641],[[cllocation alloc] initwithlatitude:40.454109 longitude:-79.944487],[[cllocation alloc] initwithlatitude:40.455858 longitude:-79.938618],[[cllocation alloc] initwithlatitude:40.457224 longitude:-79.934069],[[cllocation alloc] initwithlatitude:40.454777 longitude:-79.9932543],[[cllocation alloc] initwithlatitude:40.453458 longitude:-79.931763],[[cllocation alloc] initwithlatitude:40.452099 longitude:-79.931148],[[cllocation alloc] initwithlatitude:40.451258 longitude:-79.930633],[[cllocation alloc] initwithlatitude:40.449866 longitude:-79.929729],[[cllocation alloc] initwithlatitude:40.448956 longitude:-79.932543],[[cllocation alloc] initwithlatitude:40.44846 longitude:-79.934185],[[cllocation alloc] initwithlatitude:40.447919 longitude:-79.937028], nil]; if (xapp.aroute && xapp.aroute .count > 0) {      cgcontextref context = uigraphicsgetcurrentcontext();      cgcontextsetstrokecolorwithcolor(context, [uicolor redcolor].cgcolor);     cgcontextsetrgbfillcolor(context, 0.0, 0.0, 1.0, 1.0);     cgcontextsetalpha(context, 0.5);      cgcontextsetlinewidth(context, polyline_width);      (int = 0; < xapp.aroute .count; i++) {          cllocation* location =(cllocation*) [xapp.aroute  objectatindex:i];         cllocationcoordinate2d coordinate=cllocationcoordinate2dmake(location.coordinate.latitude,location.coordinate.longitude);         nslog(@"%f%f",coordinate.longitude,coordinate.latitude);         cgpoint point = [_mapview convertcoordinate:coordinate topointtoview:_mapview];         if (i == 0)             cgcontextmovetopoint(context, point.x, point.y);         else             cgcontextaddlinetopoint(context, point.x, point.y);          nslog(@"%f%f",point.x,point.y);             }      cgcontextstrokepath(context);  } 

here problem convertcoordinate not working me.. i'm getting cgpoints {0,0} coordinates

i write code draw line on mapview bellow...

-(void) updaterouteview  {     cgcontextref context =  cgbitmapcontextcreate(nil,                                                    routeview.frame.size.width,                                                    routeview.frame.size.height,                                                    8,                                                    4 * routeview.frame.size.width,                                                   cgcolorspacecreatedevicergb(),                                                   kcgimagealphapremultipliedlast);      cgcontextsetstrokecolorwithcolor(context, linecolor.cgcolor);     cgcontextsetrgbfillcolor(context, 0.0, 0.0, 1.0, 1.0);     cgcontextsetlinewidth(context, 3.0);      for(int = 0; < routes.count; i++)      {         cllocation* location1 = [routes objectatindex:i];         cgpoint point = [mapview convertcoordinate:location1.coordinate topointtoview:routeview];         if(i == 0)          {             cgcontextmovetopoint(context, point.x, routeview.frame.size.height - point.y);         }         else          {             cgcontextaddlinetopoint(context, point.x, routeview.frame.size.height - point.y);         }     }      cgcontextstrokepath(context);      cgimageref image = cgbitmapcontextcreateimage(context);     uiimage* img = [uiimage imagewithcgimage:image];      routeview.image = img;     cgcontextrelease(context);  } 

see demo serendipitor

may idea this....

i hope helpful you...


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -