Identify if coordinate set is within a radius in Android

13

I want to delimit a radius from a central coordinate (the red marker in the figure) and, from a set of coordinates (the green markers), check if they are within the area delimited by this radius. >

  • How to identify, from a set of coordinates (latitude and longitude), these or which of them are within a given radius used as a reference? li>
  • Is it possible to configure the size of this radius?

I need a real example, a sample project on Android.

    
asked by anonymous 25.03.2015 / 02:11

2 answers

18

As you said, if storage is being done in a MySQL database on the server, I imagine you have a call via webservice to fetch this data. Therefore, you can determine your question in query .

Assuming you have a table with the columns lat and lng for the coordinates and passing its reference point (here I will use as an example the values -19.83996 and -43.94910 ), just do something like this:

SELECT *, (6371 *
        acos(
            cos(radians(-19.83996)) *
            cos(radians(lat)) *
            cos(radians(-43.94910) - radians(lng)) +
            sin(radians(-19.83996)) *
            sin(radians(lat))
        )) AS distance
FROM tabela HAVING distance <= 5

This will get you all locations that are within

25.03.2015 / 13:52
1

More gold !!!

SELECT *,(RAIO_TERRESTRE * 
        acos(
         cos(radians(PARAMETRO_LATITUDE)) * 
         cos(radians(COLUNA_LATITUDE)) * 
         cos(radians(PARAMETRO_LONGITUDE) - radians(COLUNA_LONGITUDE)) + 
         sin(radians(PARAMETRO_LATITUDE)) * 
         sin(radians(COLUNA_LATITUDE))
      )) AS CAMPOLATITUDE
FROM TABELA HAVING CAMPOLATITUDE <= KM
    
14.05.2018 / 23:39