{ "id": "116310", "key": "TIMOB-14343", "fields": { "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2013-06-21T10:00:40.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "ios", "sqlite" ], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-02-28T20:03:42.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "For the last 4 major versions I have been adding this patch to PlausibleDatabase files, it's about time this was added to the official branch of Titanium.\r\n\r\nThe following added to the top of \"PLSqliteDatabase.m\"\r\n\r\n{code} \r\n#define DEG2RAD(degrees) (degrees * 0.01745327) // degrees * pi over 180\r\n\r\nstatic void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv) {\r\n \r\n assert(argc == 4);\r\n \r\n if (sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL || sqlite3_value_type(argv[2]) == SQLITE_NULL || sqlite3_value_type(argv[3]) == SQLITE_NULL) {\r\n sqlite3_result_null(context);\r\n return;\r\n }\r\n \r\n double lat1 = sqlite3_value_double(argv[0]);\r\n double lon1 = sqlite3_value_double(argv[1]);\r\n double lat2 = sqlite3_value_double(argv[2]);\r\n double lon2 = sqlite3_value_double(argv[3]);\r\n \r\n double lat1rad = DEG2RAD(lat1);\r\n double lat2rad = DEG2RAD(lat2);\r\n \r\n sqlite3_result_double(context, acos(sin(lat1rad) * sin(lat2rad) + cos(lat1rad) * cos(lat2rad) * cos(DEG2RAD(lon2) - DEG2RAD(lon1))) * 6378.1);\r\n}\r\n{code} \r\nAnd in the function \"openAndReturnError\" just before the return:\r\n\r\n{code} sqlite3_create_function(_sqlite, \"distance\", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL); {code} \r\n\r\nThen in the \"PLSqliteDatabase.h\" file at the very end of the file before the @end:\r\n\r\n{code}\r\n-(void)distanceFunc:(id)args;\r\n\r\n@end\r\n\r\n#endif\r\n{code}", "attachment": [ { "id": "40125", "filename": "PLSqliteDatabase.h", "author": { "name": "iantearle", "key": "iantearle", "displayName": "Ian Tearle", "active": true, "timeZone": "Europe/London" }, "created": "2013-06-21T10:00:40.000+0000", "size": 2461, "mimeType": "application/octet-stream" }, { "id": "40126", "filename": "PLSqliteDatabase.m", "author": { "name": "iantearle", "key": "iantearle", "displayName": "Ian Tearle", "active": true, "timeZone": "Europe/London" }, "created": "2013-06-21T10:00:40.000+0000", "size": 16518, "mimeType": "application/octet-stream" } ], "flagged": false, "summary": "TiAPI: PlausibleDatabase SQLite Distance function", "creator": { "name": "iantearle", "key": "iantearle", "displayName": "Ian Tearle", "active": true, "timeZone": "Europe/London" }, "subtasks": [], "reporter": { "name": "iantearle", "key": "iantearle", "displayName": "Ian Tearle", "active": true, "timeZone": "Europe/London" }, "environment": "iOS", "comment": { "comments": [], "maxResults": 0, "total": 0, "startAt": 0 } } }