android-如何检查位置是在特殊区域?

时间:2017-08-26 06:04:40

标签: android google-maps currentlocation

我想在特定区域的Android应用中使用谷歌地图。例如在特殊国家。如何检查我当前所在的位置?

更新

例如如何检查我是否在新德里市

2 个答案:

答案 0 :(得分:4)

您可以尝试使用LatLngBoundsLatLngBounds.contains()

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

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

答案 1 :(得分:1)

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);

更多信息:Displaying a Location Address