top of page

Nearby Places Android App

Updated: Jul 20, 2021

Introduction:

APK uses google maps to get location of nearby places like market, hotel, pharmacy, hospital, bank, bakery, store, restaurant. And can find distance and time between source and destination. Check traffic situation and street view of any location.


Concepts Used:

Major use is of Google Maps in the APK, so we will deal with most of its functionalities.


APK uses two Custom Adapters:

Country Adapter :

Country Adapter extends Recycler View Adapter, Country Adapter Constructor takes arguments like countrylist which is a list of objects whose properties are name, vicinity, latitude, longitude. It also takes source latitude and longitude as arguments and the context.


public CountryAdapter(Context c, ArrayList<SingleRow> countryList, ArrayList<String> nameList, ArrayList<String> vicinityList, String source_lat, String source_lng)
{
 this.c=c;
 this.countryList = countryList;
 this.source_lat = source_lat;
 this.source_lng = source_lng;
}

And onCreateViewHolder is inflated using card_layout which show information like title, address and distance. And the distance is calculated using a function CalculationByDistance(LatLng StartP, LatLng EndP) which takes input as starting Lat and Long, ending Lat and Long.


public CountryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
   View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_layout,parent,false);
   CountryViewHolder countryViewHolder = new CountryViewHolder(view);
 return countryViewHolder;

}

double CalculationByDistance(LatLng StartP, LatLng EndP) {

int Radius=6371;//radius of earth in Km

double lat1 = StartP.latitude;

double lat2 = EndP.latitude;

double lon1 = StartP.longitude;

double lon2 = EndP.longitude;

double dLat = Math.toRadians(lat2-lat1);

double dLon = Math.toRadians(lon2-lon1);

double a = Math.sin(dLat/2) * Math.sin(dLat/2) +

Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *

Math.sin(dLon/2) * Math.sin(dLon/2);

double c = 2 * Math.asin(Math.sqrt(a));

double valueResult= Radius*c;

double km=valueResult/1;

DecimalFormat newFormat = new DecimalFormat("####");

int kmInDec = Integer.valueOf(newFormat.format(km));

double meter=valueResult%1000;

int meterInDec= Integer.valueOf(newFormat.format(meter));


return meter;

}


Distance Adapter:

The second adapter which we used is Distance Adapter which also extends RecyclerView.Adapter. It’s constructor takes arguments like distance, duration and Context.

onCreateViewHolder inflates distance layout which contains distance and duration.

@Override

public DistanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.distancelayout,parent,false);

DistanceAdapter.DistanceViewHolder distanceViewHolder = new DistanceAdapter.DistanceViewHolder(view);

return distanceViewHolder;

}


MapDetailsActivity:

This activity implements OnMapReadyCallback, LocationListener.

public interface OnMapReadyCallback

Callback interface for when the map is ready to be used.

Once an instance of this interface is set on a MapFragment or MapView object, the onMapReady(GoogleMap) method is triggered when the map is ready to be used and provides a non-null instance of GoogleMap.

If Google Play services is not installed on the device, the user will be prompted to install it, and the onMapReady(GoogleMap) method will only be triggered when the user has installed it and returned to the app.


LocationListener

public interface LocationListener

android.location.LocationListener

Used for receiving notifications when the device location has changed. These methods are called when the listener has been registered with the LocationManager.

It contains methods like navigate(View v), requestDirections(), String getUrl(String lat1, String long1,String nearbyPlace), String getUrlUniv(String lat1, String long1,String nearbyPlace).


Data Parser:

Data parsing is a method where one string of data gets converted into a different type of data. So let's say you receive your data in raw HTML, a parser will take the said HTML and transform it into a more readable data format that can be easily read and understood.

Then we have different activities like StreetView Activity, RouteFinder Activity, NearbyLocation Activity, etc.

StreetView Activity:

This activity implements OnStreetViewPanoramaReadyCallback,LocationListener

public interface OnStreetViewPanoramaReadyCallback

Callback interface for when the Street View panorama is ready to be used.

Once an instance of this interface is set on a StreetViewPanoramaFragment or StreetViewPanoramaView object, the onStreetViewPanoramaReady(StreetViewPanorama) method is triggered when the panorama is ready to be used and provides a non-null instance of StreetViewPanorama.

If Google Play services is not installed on the device, the user will be prompted to install it, and the onStreetViewPanoramaReady(StreetViewPanorama) method will only be triggered when the user has installed it and returned to the app.


Abstract void onStreetViewPanoramaReady(StreetViewPanorama panorama) Called when the Street View panorama is ready to be used.

RouteFinder Activity:

This activity implements OnMapReadyCallback, LocationListener. Uses a method String getStringAddress(Double lat,Double lng), this method uses geocoder, which is a class for handling geocoding and reverse geocoding. Geocoding is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinate. Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a (partial) address.


NearbyLocation Activity:

This activity also implements LocationListener, This activity uses GetNearByPlacesData which extends AsyncTask<Object,String,String> to get Places,

Places provides programmatic access to Google's database of local place and business information, as well as the device's current place.



If you are looking for Android Assignment Help or Homework Help? Codersarts Androidassignment help expert will provides best quality plagiarism free solution at affordable price. We are available 24 * 7 online to assist you. You may chat with us through website chat or email or can fill contact form.

bottom of page