Saturday, 15 August 2015

ios - starting with mkmap and need to show real time route between two points -



ios - starting with mkmap and need to show real time route between two points -

i new ios development , developing iphone app in need utilize mkmapview. in need show route between 2 or more pin points.

please help same.

use below code draw pins on mkmapview. here have used san francisco city's 2 near locations points.

- (void) setdirectionlocation { cllocationcoordinate2d location = cllocationcoordinate2dmake(37.79520324238053, -122.40283370018005); mkcoordinateregion region; part = mkcoordinateregionmake(location, mkcoordinatespanmake(0.02, 0.02)); mkcoordinateregion adjustedregion = [self.mapview regionthatfits:region]; [self.mapview setregion:adjustedregion animated:yes]; cllocationcoordinate2d tocoordinate = cllocationcoordinate2dmake(37.802932, -122.401612); mkplacemark *fromplacemark = [[mkplacemark alloc] initwithcoordinate:location addressdictionary:nil]; mkplacemark *toplacemark = [[mkplacemark alloc] initwithcoordinate:tocoordinate addressdictionary:nil]; mkmapitem *fromitem = [[mkmapitem alloc] initwithplacemark:fromplacemark]; mkmapitem *toitem = [[mkmapitem alloc] initwithplacemark:toplacemark]; mkdirectionsrequest *request = [[mkdirectionsrequest alloc] init]; request.source = fromitem; request.destination = toitem; request.requestsalternateroutes = yes; mkdirections *directions = [[mkdirections alloc] initwithrequest:request]; [directions calculatedirectionswithcompletionhandler: ^(mkdirectionsresponse *response, nserror *error) { if (!error) { mkroute *route = response.routes[0]; [self.mapview addoverlay:route.polyline]; // drop pin mkpointannotation *startpin = [[mkpointannotation alloc] init]; startpin.coordinate = location; startpin.title = @"start"; [self.mapview addannotation:startpin]; mkpointannotation *endpin = [[mkpointannotation alloc] init]; endpin.coordinate = tocoordinate; endpin.title = @"end"; [self.mapview addannotation:endpin]; } else { nslog(@"direction not found."); } }]; }

ios objective-c storyboard mkmapview

No comments:

Post a Comment