[TIMOB-10782] iOS: Native Haversine formula for calculating distances inside Ti.Geolocation and Ti.Database
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Trivial |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 3.0.0 |
Fix Version/s | n/a |
Components | iOS |
Labels | api |
Reporter | Ygor Lemos |
Assignee | Unknown |
Created | 2012-08-22T16:32:39.000+0000 |
Updated | 2018-02-28T20:03:33.000+0000 |
Description
Implement a native Haversine function in ObjC or Java for better performance, allowing developers willing to implement Geolocation with distance calculations (which most do) usage to a more efficient and fast Haversine implementation.
We could map against something like:
Ti.Geolocation.haversine({lat1: xxx, long1:xxx, lat2: xxx, long2: xxx, unit: 'metric'})
for calculating the distance between two points in the sphere.
There are implementation examples of the Haversine formula here:
http://www.movable-type.co.uk/scripts/latlong.html
on the wikipedia there are examples in several computer languages:
http://en.wikipedia.org/wiki/Haversine_formula
Also, there is a formula called Vincentys which is way more precise (millimetric precision) but also consumes more CPU due to the fact that it considers the real shape of the earth while Haversine considers the earth as a regular sphere (thus having an acceptable error margin).
we could also made something like *Ti.Geolocation.vincenty()* for more precise stuff.
Follows Vincenty's Formula explanations:
http://www.movable-type.co.uk/scripts/latlong-vincenty.html
http://en.wikipedia.org/wiki/Vincenty%27s_formulae
------
Apart all of that we should really have a native SQL haversine formula for users that store latitude and longitude data in SQLite Databases.
So we could make queries like:
*SELECT * FROM Locations ORDER BY distance(Latitude, Longitude, 51.503357, -0.1199)*
There are ways of implementing custom functions inside the SQLite database, at least on ObjC, thus allowing for Geodesic queries inside the DB...
Take a look at this Obj-C + SQLite implementation:
http://www.thismuchiknow.co.uk/?p=71
More on the SQLite native functions: http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html