Manfred,
To get the closest place to your current location in a MySQL database (this is what I have used - may help you - should easily convert to SQLite) you use a "thing" called the Haversine formula. (
wikipedia)
Here is an example MySQL procedure that I call from my b4a app. I hope this helps you.
The parameters are:
Latitude - Your Current Position Latitude
Longitude - Your current Position Longitude
RadiusIn - The radius in km from your current position you wish to search
NumRecs - The number of MySQL records you want returned
This particular one returns the number of records or less that you specify within the radius you have specified in km's from your current position. I use it for a Closest Pharmacy lookup.
PROCEDURE ListingSystem2.GetPharmacies(IN Latitude VARCHAR(255), IN Longitude VARCHAR(255), IN RadiusIn INT, IN NumRecs INT)
COMMENT 'Procedure to get Closest Pharmacies using Haversine formula'
SELECT g.listing_refid,g.lat,g.lng,g.address_content,g.address_city, g.address_state, g.address_postcode, g.phone, g.email, g.status, Round(p.distance_unit * DEGREES(ACos(Cos(RADIANS(p.latpoint)) * Cos(RADIANS(g.lat)) * Cos(RADIANS(p.longpoint) - RADIANS(g.lng)) + Sin(RADIANS(p.latpoint)) * Sin(RADIANS(g.lat)))),2) As distance_in_km
FROM yellowpages_listings As g
JOIN (Select Latitude As latpoint, Longitude As longpoint, RadiusIn As radius, 111.045 As distance_unit) As p
WHERE g.lat
BETWEEN p.latpoint - (p.radius / p.distance_unit)
AND p.latpoint + (p.radius / p.distance_unit)
AND g.lng
BETWEEN p.longpoint - (p.radius / (p.distance_unit * Cos(RADIANS(p.latpoint))))
AND p.longpoint + (p.radius / (p.distance_unit * Cos(RADIANS(p.latpoint))))
AND g.status = 'T'
ORDER BY distance_in_km
LIMIT NumRecs
The table looks like this:
CREATE TABLE ListingSystem2.yellowpages_listings (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
listing_refid VARCHAR(255) DEFAULT NULL,
lat VARCHAR(255) DEFAULT NULL,
lng VARCHAR(255) DEFAULT NULL,
address_postcode VARCHAR(255) DEFAULT NULL,
address_content TEXT DEFAULT NULL,
address_city VARCHAR(255) DEFAULT NULL,
address_state VARCHAR(255) DEFAULT NULL,
phone VARCHAR(255) DEFAULT NULL,
email VARCHAR(255) DEFAULT NULL,
status ENUM('T','F','E') NOT NULL DEFAULT 'F',
PRIMARY KEY (id)
)
ENGINE = INNODB
AUTO_INCREMENT = 0
AVG_ROW_LENGTH = 230
CHARACTER SET utf8
COLLATE utf8_general_ci;
Have Fun !!