iphone - How to get directions between two locations in the form of text in iOS -
i remember there google api tooks either lat,long or from&to address, if load url on webview, used show directions between 2 points in form of text. can 1 provide me api text based directions. don't want draw line on maps, want show text.
mkplacemark *source = [[mkplacemark alloc]initwithcoordinate:cllocationcoordinate2dmake(37.776142, -122.424774) addressdictionary:[nsdictionary dictionarywithobjectsandkeys:@"",@"", nil] ]; mkmapitem *srcmapitem = [[mkmapitem alloc]initwithplacemark:source]; [srcmapitem setname:@""]; mkplacemark *destination = [[mkplacemark alloc]initwithcoordinate:cllocationcoordinate2dmake(37.73787, -122.373962) addressdictionary:[nsdictionary dictionarywithobjectsandkeys:@"",@"", nil] ]; mkmapitem *distmapitem = [[mkmapitem alloc]initwithplacemark:destination]; [distmapitem setname:@""]; mkdirectionsrequest *request = [[mkdirectionsrequest alloc]init]; [request setsource:srcmapitem]; [request setdestination:distmapitem]; [request settransporttype:mkdirectionstransporttypeany]; mkdirections *direction = [[mkdirections alloc]initwithrequest:request]; [direction calculatedirectionswithcompletionhandler:^(mkdirectionsresponse *response, nserror *error) { nslog(@"response = %@",response); nsarray *arrroutes = [response routes]; [arrroutes enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop) { mkroute *rout = obj; mkpolyline *line = [rout polyline]; [mapview addoverlay:line]; nslog(@"rout name : %@",rout.name); nslog(@"total distance (in meters) :%f",rout.distance); nsarray *steps = [rout steps]; nslog(@"total steps : %lu",(unsigned long)[steps count]); nsmutablearray *stepsarray=[[nsmutablearray alloc] init]; [steps enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop) { nslog(@"rout instruction : %@",[obj instructions]); nslog(@"rout distance : %f",[obj distance]); [stepsarray addobject:[obj instructions]]; }]; [self myshowdirections:response]; self.steps.text=[nsstring stringwithformat:@"%@",stepsarray]; you can use , want.
Comments
Post a Comment