Eğer adresi almak ve adrese gelen enlem ve boylam alabilir:
Geocoder coder = new Geocoder(this);
List<Address> address;
try {
address = coder.getFromLocationName(strAddress,5);
if (address == null) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
}
Ve sonra konumu ile
if (distance(mylocation.latitude, mylocation.longitude, location.getLatitude(), location.getLongitude()) < 0.1) { // if distance < 0.1
// launch the activity
}else {
finish();
}
/** calculates the distance between two locations in MILES */
private double distance(double lat1, double lng1, double lat2, double lng2) {
double earthRadius = 3958.75; // in miles, change to 6371 for kilometers
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double sindLat = Math.sin(dLat/2);
double sindLng = Math.sin(dLng/2);
double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)
* Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
return dist;
}
EDIT karşılaştırmak: @FelipeMosso diyorduk Ayrıca, iki konum arasındaki metre mesafeyi veya distanceTo arasındaki mesafeyi hesaplayan distanceBetween'u da kullanabilirsiniz. hedefleme noktası:
Creating and Monitoring Geofences görüyor musunuz? – Prmths
Belki bu size yardımcı olabilir: http://stackoverflow.com/questions/3652951/google-maps-api-get-coordinates-of-address. Temel olarak iki set koordinatı karşılaştırmanız ve eğer bu iki çiftin birbirlerine yeterince yakın olup olmadığını anlamanız gerekir. – Izmaki
@Prmths uygulaması sadece açık değil :) –