Limit Android user location in city perimeters

I am creating an application where I need to apply borders at the user's location (Lat, Lng) to be in urban perimeters such as Uber. How can I achieve this?

This is the one when in the perimeters of the city

enter image description here

This is not in an urban or Uber service area.

enter image description here

I tried this approach. I use a geocoder and select the location address and the corresponding city parameters.

        addresses = geocoder.getFromLocation(lat, lon, 1); 
        if (addresses != null && !addresses.isEmpty()) {
            String address = addresses.get(0).getAddressLine(0);
            String city = addresses.get(0).getLocality();
            String state = addresses.get(0).getAdminArea();
            String country = addresses.get(0).getCountryName();
            String postalCode = addresses.get(0).getPostalCode();
            String knownName = addresses.get(0).getFeatureName();
        }

Can i use geofencing? If so, how?

+4
source share

Source: https://habr.com/ru/post/1614678/


All Articles