简体   繁体   中英

Spatial request using SQLite database on iPhone

I want to develop an iPhone application using geolocation by using locally stored spatial data.

The tricky part of such an application is the response to the request "I want the x nearest points around me". This because the data have to be ordered, and the ordering criteria is the distance on a sphere (yes earth is not flat ^^). So an efficient algorithm is quite complex.

Spatial data are stored locally on my application (hence the use of sqlLite) so I can not use libs such as MyGis or PostGis. On SqlLite I saw "SpatiaLite" but it seems that it is not very convenient to use with iPhone.

Anyone know an library to do that easily ?... or a convenient way to perform this task ?

In your SQL query, you need to calculate the distance between your given point and each stored point, order the results by that value and return the first x rows.

You don't state how many data points there are, or how dispersed they are - if this is a large data set then this approach will be expensive and you will want to look at ways of how to identify a likely subset of points before calculating all the distances, and/or a caching/pre-calculation technique to prevent you calculating the same information for a user in the same place over and over. Because you will essentially be running a function on every data row, indexes can't be used.

There are lots of good references on how to calulate the distance between two points, eg:

http://www.mathopenref.com/coorddist.html

The spherical nature of the earth won't have much impact on the distances unless the data is particularly sensitive to precision, but if it is, there are other factors such as change in altitude that will also have an effect on real distances.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM