android-How to check location is in special area?

2.2k views Asked by At

I want to use google map in my android app in specific area. for example in special country. How can I check that my current location is in that place?

updates:

for example how to check that I am in New Delhi city

2

There are 2 answers

0
Aniruddha Bera On BEST ANSWER

You can try using LatLngBounds and LatLngBounds.contains()

private LatLngBounds NewDelhi = new LatLngBounds(your special area SE LatLng , NE LatLng );

if(NewDelhi.contains(your location LatLng)) 
//Do something 
0
RonTLV On

Get city name from Location:

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(myLocation.getLatitude(), myLocation.getLongitude(), 1);
String cityName = addresses.get(0).getAddressLine(0);
//String stateName = addresses.get(0).getAddressLine(1);
//String countryName = addresses.get(0).getAddressLine(2);

For more: Displaying a Location Address