iphone - Using distanceFromLocation: on none CLLocation objects? -


i have defined class called fglocation conforms mkannotation protocol, trying measure distance between 2 of these objects. noticed use method distancefromlocation: defined method cllocation class. can see below creating 2 temp cllocation objects calculation, can't thinking maybe missing better / easier way. have comments on doing or how might better?

// there better way this? fglocation *root = [annotations objectatindex:counter-1]; fglocation *leaf = [annotations objectatindex:counter];  cllocation *rootlocation = [[cllocation alloc] initwithlatitude:[root coordinate].latitude longitude:[root coordinate].longitude]; cllocation *leaflocation = [[cllocation alloc] initwithlatitude:[leaf coordinate].latitude longitude:[leaf coordinate].longitude];                                 cllocationdistance thisdistance = [rootlocation distancefromlocation:leaflocation]; [rootlocation release]; [leaflocation release]; 

nb: fglocation object defined (see below) noticed in docs should not subclassing cllocation.

@interface fglocation : nsobject <mkannotation> { 

i think doing fair approach, possible exception might want implement sort of caching mechanism/threshold recalculation if doing or on lot of points. calculating distances accurately involves non-euclidean geometry , computationally expensive. http://en.wikipedia.org/wiki/haversine_formula

depending on points located on globe , whether or not precision highly important, can fudge things pretending working in euclidean space , leveraging pythagorean theorem. have used kind of scheme create gross filter on large dataset , resorted more precise calculations on points pass filter.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -