android-How to check location is in special area?

和自甴很熟 提交于 2019-12-08 03:30:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!