问题
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
回答1:
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
回答2:
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
来源:https://stackoverflow.com/questions/45892423/android-how-to-check-location-is-in-special-area