Jonathan_Medeiros 11 de jul. de 2017
Já tentou algo como o código abaixo:
if (( lat_1 >= lat_2 && lat_1 <= lat_2 ) && ( long_1 >= long_2 && long_1 <= long_2 )){
//faça isso
}
thiagodbonis 11 de jul. de 2017
@Jonathan_Medeiros eu utilizava assim,
porém falaram que não é o certo.
O certo é criar um “perímetro” como eu citei a cima, aqui abaixo vai o código das funções citadas:
/**
* Sets the blur radius ( in meters ) to use for privacy reasons
*
* @ param blurRadius the blur radius ( in meters )
*/
public void setBlurRadius ( final int blurRadius ) {
mBlurRadius = blurRadius ;
}
/**
* Calculates the difference from the start position to the end position ( in meters )
*
* @ param start the start position
* @ param end the end position
* @ return the distance in meters
*/
public static double calculateDistance ( Point start , Point end ) {
return calculateDistance ( start . latitude , start . longitude , end . latitude , end . longitude );
}
/**
* Calculates the difference from the start position to the end position ( in meters )
*
* @ param startLatitude the latitude of the start position
* @ param startLongitude the longitude of the start position
* @ param endLatitude the latitude of the end position
* @ param endLongitude the longitude of the end position
* @ return the distance in meters
*/
public static double calculateDistance ( double startLatitude , double startLongitude , double endLatitude , double endLongitude ) {
float [] results = new float [ 3 ];
Location . distanceBetween ( startLatitude , startLongitude , endLatitude , endLongitude , results );
return results [ 0 ];
}
staroski 11 de jul. de 2017
Se a distância calculada for menor que o raio, significa que está dentro do perímetro.
thiagodbonis 11 de jul. de 2017
Então irá ficar, assim ?
if ( location . calculateDistance ( lat_1 , long_1 , lat_2 , long_2 ) > location . setBlurRadius ( 10000 )){
// TODO
}
Jonathan_Medeiros 11 de jul. de 2017 2 likes
Acho que compreendi sua ideia, se de repente você utilizar o addProximityAlert() localizado dentro de LocationManager, acho que você consegue chegar no resultado esperado.
Dá uma olhada nestes Links, talvez te ajude:
Documentação.
Exemplo de uso.