6

I am developing one application where I need to create sqlite function for distance, I have two fields latitude and longitude in database, and I want to find near by locations using that function, I have developed application in iPhone, I have implemented this functionality using sqlite3_create_function by calling callback function, which will give me distance.

But the problem is: I can not be able to create function in SQLITE using android, Does anyone know better way to get nearby locations from sqlite using android?

The other problem is SQLITE does not support sin, cosine functions to calculate distance between points.

jigneshbrahmkhatri
  • 3,627
  • 2
  • 21
  • 33

1 Answers1

-3

Hello Jignesh,

In my view, there are basically two solutions to your problem.

1. Use javaScript to perform the functions

Create the necessary functions in javaScript and use the result to update/query Sqlite.

JavaScript is well suited for trigonometry; sine, cosine and tangent. JavaScript can calculate advanced mathematical problems extremely fast.

Example: Calculating the answer to the following problem

The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 +... + 10^2 = 385. The square of the sum of the first ten natural numbers is, (1 + 2 + ... + >10)^2 = 55^2 = 3025. Hence the difference between the sum of the squares of the first ten >natural numbers and the square of the sum is 3025 – 385 = 2640. Find the difference >between the sum of the squares of the first one hundred natural numbers and the square of >the sum.

function Problem_6() {
    "use strict";
    var i = 1, ns = 0, sqs = 0;
    do {
        ns += i;
        sqs += i * i;
        i += 1;
    } while (i <= 100);
    return ns * ns - sqs;
}

Answer: 25164150

This example is from Rolando Garza’s El blog de rolandog, based on his own extension to javaScript’s Global Math Object; Math.js.

References:

Mozilla’s JavaScript References for the Global Math Object:

Trigonometry—sine, cosine and tangent with JavaScript, by JJ Gifford.

2. GeoNames Database

GeoNames is an open source database over geographical information about most countries, cities, and villages in the world, including latitude and longitude as well as distances to other geo-locations.

GeoNames is available both as a webservice through a JSON API, and as downloadable tables.

2.1 Query GeoNames through JSON API

Example: Finding the nearest intersection for the given latitude/longitude

http://api.geonames.org/findNearestIntersectionOSMJSON?lat=37.451&lng=-122.18&username=demo

{"intersection":{"street2":"Curtis Street","street1":"Roble Avenue","distance":"0.08","highway2":"residential","highway1":"residential","lng":"-122.1808166","lat":"37.4506308"}}

2.2 Downloading GeoNames

Store required geo-information locally in Sqlite.

More information: http://www.geonames.org/

LarsB
  • 613
  • 5
  • 7