Search code examples
androidgoogle-mapsandroid-mapviewandroid-maps

get the georeferenced points near me, with android


I have an android application that has some georeferenced places, and I can show them all or make the query to a specific one, but I want to consult those that are nearby within a radius of 1km from my location. I think a between is used but I do not know how to do it.

criaderosMap = criaderoDao.queryBuilder()
            .where(CtlPlCriaderoDao.Properties.Latitud.isNotNull()).list();

It is the same as:

select * from ctlCriadero where latitud is no null

Solution

  • You can construct a query by your own. Following is one of the example.

        select
        latitud ,
        longitude,
        ( 3959 * acos(  cos( radians(37) )
                      * cos( radians( latitud ) )
                      * cos( radians( longitude) - radians(YourLongitude) )
                      + sin( radians(YourLatitude) ) * sin( radians( latitud ) )
                     )
        ) AS distance
    FROM
        ctlCriadero
    HAVING
        distance < 1000
    ORDER BY
        distance
    LIMIT
        0 , 50
    

    Credit: @daroczig