Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:18:40+00:00 2026-06-01T19:18:40+00:00

I wrote a simple web application that lets you mark flea market stands on

  • 0

I wrote a simple web application that lets you mark flea market stands on a google map.
Each stand is stored in a sqlite3 database with its geolocation and other information.
This is the CREATE statement for the stands table:

CREATE TABLE stands (
id INTEGER PRIMARY_KEY,
name TEXT,
address TEXT,
u REAL,
v REAL,
);

u and v are respectively Latitude and Longitude.
Additionally I have a cities table that stores the name and geographic bounds of each city which host a stand. This is used to let users quickly navigate between cities.

CREATE TABLE cities
(name TEXT PRIMARY_KEY,
u_min REAL,
u_max REAL,
v_min REAL,
v_max REAL);

When a new stand is added, a new row is added to the cities table or if the stand is in a known city, only the bounds of the city are updated if needed.

Here are some sample stands:

592077673|Kierrätystori Rovaniemellä|Urheilukatu 1, 96100 Rovaniemi, Suomi|66.4978306921681|25.7220569153442
1321495145|Kruununhaka|Liisankatu, 00170 Helsinki, Suomi|60.1742596|24.9555782    
571688977|Viikki asukastalo LAVAn edusta|Biologinkatu 5, 00790 Helsinki, Suomi|60.2342312|25.04058
563089951|Hämeentie 156|Hämeentie 156, 00560 Helsinki, Suomi|60.2130467082539|24.9785856067459    
518892420|Joensuu - Ilosaari|Siltakatu 1, 80100 Joensuu, Finland|62.5990455742272|29.7706540507875

and cities:

    Rovaniemi|66.4978306921681|66.4978306921681|25.7220569153442|25.7220569153442
Helsinki|60.1577049447137|60.2556221042622|24.9216988767212|25.0662129772156
Järvenpää|60.4513724|60.4513724|25.0819323000001|25.0819323000001
Joensuu|62.5990455742272|62.5990653244875|29.7706540507874|29.7706540507875
Vantaa|60.2731724937748|60.2731724937748|24.9571491285278|24.9571491285278

The issue I’m having is retrieving the the number of stands per cities.
So far I’ve been using the following query:

SELECT cities.name AS city,
  cities.u_min,
  cities.u_max,
  cities.v_min,
  cities.v_max,
  count(stands.id) AS count
FROM cities
LEFT OUTER JOIN stands
  ON ((stands.u BETWEEN cities.u_min AND cities.u_max)
    AND(stands.v BETWEEN cities.v_min AND cities.v_max))
GROUP BY cities.name;

This returns:

Helsinki|60.1577049447137|60.2556221042622|24.9216988767212|25.0662129772156|9
**Joensuu|62.5990455742272|62.5990653244875|29.7706540507874|29.7706540507875|0**
Järvenpää|60.4513724|60.4513724|25.0819323000001|25.0819323000001|1
Rovaniemi|66.4978306921681|66.4978306921681|25.7220569153442|25.7220569153442|1
Vantaa|60.2731724937748|60.2731724937748|24.9571491285278|24.9571491285278|1

Which is not correct as the city named Joensuu does have 1 stand in its boundaries:

518892420|Joensuu - Ilosaari|Siltakatu 1, 80100 Joensuu, Finland|62.5990455742272|29.7706540507875

But the following query returns the expected stand:

SELECT * FROM stands where u between 62.5990455742272 and 62.5990653244875 and v between 29.7706540507874 and 29.7706540507875;

I really can’t understand what is going wrong here.
Any help would be greatly appreciated.

By the way, I imported this database to Mysql and the same thing happens so I doubt this is a sqlite3 bug.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:18:42+00:00Added an answer on June 1, 2026 at 7:18 pm

    I think this has to do with floating point precision error. One of the ways to deal with such problems is to introduce a small number and add it to your boundaries to make them a little wider – that eliminates precision errors.

    One approach is to widen boundaries in every query directly:

    SET @e = 0.0000000000001;
    
    SELECT cities.name AS city,
      cities.u_min,
      cities.u_max,
      cities.v_min,
      cities.v_max,
      count(stands.id) AS count
    FROM cities
    LEFT OUTER JOIN stands
      ON ((stands.u BETWEEN cities.u_min - @e AND cities.u_max + @e)
        AND(stands.v BETWEEN cities.v_min - @e AND cities.v_max + @e))
    GROUP BY cities.name;
    

    Another approach is to store the widened boundaries in the cities table:

    SET @e = 0.0000000000001;
    
    UPDATE cities
    SET cities.u_min = cities.u_min - @e,
      cities.u_max = cities.u_max + @e,
      cities.v_min = cities.v_min - @e,
      cities.v_max = cities.v_max + @e;
    

    P.S. I am not sure if the variable syntax works in SQLite, but if doesn’t, just substitute all @e with 0.0000000000001.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple web application that have to read and write in
For debugging i wrote a really simple Web-Application which contains only a simple JSP
I wrote a very simple web form that allows my user to view text
I wrote simple silverlight web application using the default ASP test page. If there
I am trying to write a simple application that loads images that are stored
I have simple web application called App that is secured with Windows Authentication. I
I wrote a simple program in java web forms but i am receiving the
I'm writing a simple web app in PHP that needs to have write access
I wrote a simple web app to let user input data as they walk
I have a web application that creates directories. The application works fine when creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.