I can't tell you how to add that to an Android app, at least not without
doing a fair amount of experimenting that I really don't have the energy
to do at the moment, but I will give you some optimization advice instead.
I suggest that you reduce the maximum number of results returned in your
query by limiting the rows to those within a particular box as defined
by a certain number of degrees positive and negative relative to the
queried longitude and latitude. The reason is that calculating the
distance between any two points in a query is going to be CPU intensive
and can take quite a bit of time. This is especially true if you have
hundreds, thousands, or millions of rows: each matching row will need to
have the distance calculation performed on it, at least once, possibly
twice considering you may want the distance to be included in the search
result, not just using it to sort. (I haven't really tried with SQLite,
but you may or may not be able to sort based on a calculated or function
result column... so "select item_id, longitude, latitude,
calcdistance(longitude, latitude, -0.1199, 51.5053357) as distance from
whatevertable order by distance" may or may not work.)
What I did in one app that used the Google Maps API is get the latitude
span and the longitude span, divide both numbers in half, and use those
to make the device location (returned by GPS) the center of a search
box. That way any row having a latitude and longitude that are within
that box are eligible to have the distance calculated and be returned in
the data I presented to my users. The query was something like this :
select item_id, longitude, latitude from mytable where (latitude >=
minLatitude and latitude <=maxLatitude) and (longitude >= minLongitude
and longitude <= maxLongitude)
With that much said, I'll leave it up to you to figure out the details,
whether you want to have a fixed range of degrees to search on, how to
accomplish that, and how to convert that to a user friendly interface,
or whether you want to pay me any heed at all.
Raymond
On 10/01/2012 09:34 AM, saex wrote:
How can i add that function to my sqlite database in Android?
and how can i use it ?
thanks
El lunes, 1 de octubre de 2012 14:11:06 UTC+2, RichardC escribió:
http://stackoverflow.com/questions/3168904/sql-query-to-query-nearby-points-of-interest-based-on-lat-long-sqlite
<http://stackoverflow.com/questions/3168904/sql-query-to-query-nearby-points-of-interest-based-on-lat-long-sqlite>
On Monday, October 1, 2012 12:53:58 PM UTC+1, saex wrote:
I must obtain a SQLite SQL Sentence for ordering by nearest
latitude and longitude coordinates, given a initial location.
THis is a example sentence for my table in the sqlite database:
|SELECT id, name, lat, lng FROM items
|
I must achieve this with SQLite, and with that table. I can't
use another techniques because this is for a existen SQlite
database that i can't change.
Exists a way to achieve this with Android and SQlite? I
checked a lot of stackoverflow posts and i didn't find the way
to achieve that
Thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Raymond Rodgers
http://www.badlucksoft.com/
http://anevilgeni.us/
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en