android-如何查看位置是否在特殊区域?
android-How to check location is in special area?
我想在特定区域的 android 应用程序中使用 google 地图。例如在特殊国家。如何检查我的当前位置是否在那个地方?
更新:
例如如何检查我在新德里市
从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);
您可以尝试使用 LatLngBounds
和 LatLngBounds.contains()
private LatLngBounds NewDelhi = new LatLngBounds(your special area SE LatLng , NE LatLng );
if(NewDelhi.contains(your location LatLng))
//Do something
我想在特定区域的 android 应用程序中使用 google 地图。例如在特殊国家。如何检查我的当前位置是否在那个地方?
更新:
例如如何检查我在新德里市
从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);
您可以尝试使用 LatLngBounds
和 LatLngBounds.contains()
private LatLngBounds NewDelhi = new LatLngBounds(your special area SE LatLng , NE LatLng );
if(NewDelhi.contains(your location LatLng))
//Do something