Tuesday, 15 April 2014

ios - Get all latitudes and longitudes between source and destination coordinates in iPhone -



ios - Get all latitudes and longitudes between source and destination coordinates in iPhone -

i want retrieve latitudes , longitudes between source , destination coordinates.i know can create path between source , destination coordinates want latitudes , longitudes between them purpose of user movement.i using mkmapview show coordinates , cllocationmanager retrieve current location.i new in iphone.i searched question did not accurate results.please help me.

this high school algebra problem. if have point , point b (in views coordinate system) can find equation describes line between two. you'll want utilize point slope formula. 1 time have equation describes line can find points between them, there infinite number of points on line. you'll have decide level of of accuracy want. anyways simple loop point a's x point b's x, evaluating equation , solving y @ each iteration should yield set of points. can utilize convertpoint method mkmapview lat , long.

- (cllocationcoordinate2d)convertpoint:(cgpoint)point tocoordinatefromview:(uiview *)view

edit: update concrete example

this assuming have mkmapview instance someplace. should go within of mapview. if need more explanation might want check out mathisfun.com http://www.mathsisfun.com/algebra/line-equation-2points.html

mkmapview mapview.... //this job intialize, code belongs within //your mapview should assigned self. //point slope formula: y - y1 = m*(x - x1) //m = x-x1 / y - y1 //two points line starts @ 0,0 , goes diagonlly right @ 45 grade angle cgpoint pointa = cgpointmake(0, 0); cgpoint pointb = cgpointmake(10, 10); //find slope cgfloat m = (pointb.y - pointa.y) / (pointb.x - pointa.x); nsmutablearray *points = [[nsmutablearray alloc] init]; (int = pointa.x; <= pointb.x; i++) { //for each x value between , b utilize point slope formula find y value //since starting @ pointa (0, 0) our equation becomes //y - 0 = m * (x - 0), simplifying , solving y //y = m * (x - 0) -> y = m*x, , since increment x each time our equatio evaluate // y = m*i cgfloat y = m*i; cgpoint c = cgpointmake(i, y); cllocationcoordinate2d coordinate = [mapview convertpoint:c tocoordinatefromview:self.view]; //for simplicity in adding array convert cllocation object since nsarray can hold objects cllocation *location = [[cllocation alloc] initwithlatitude:coordinate.latitude longitude:coordinate.longitude]; [points addobject:location]; }

ios objective-c ios7

No comments:

Post a Comment