Commit 6ebb89ee authored by Chathura IT19243986's avatar Chathura IT19243986

Upload New File

parent d73fbe18
package com.example.peopluz1;
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.location.Location;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import com.example.peopluz1.Model.PlaceModel;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.libraries.places.api.Places;
import com.google.android.libraries.places.api.model.Place;
import com.google.android.libraries.places.api.model.PlaceLikelihood;
import com.google.android.libraries.places.api.net.FindCurrentPlaceRequest;
import com.google.android.libraries.places.api.net.FindCurrentPlaceResponse;
import com.google.android.libraries.places.api.net.PlacesClient;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executor;
public class CheckLocation {
// private GoogleMap mMap;
// // New variables for Current Place Picker
// //private static final String TAG = "MapsActivity";
// ListView lstPlaces;
// private PlacesClient mPlacesClient;
// private FusedLocationProviderClient mFusedLocationProviderClient;
//
// // The geographical location where the device is currently located. That is, the last-known
// // location retrieved by the Fused Location Provider.
// private Location mLastKnownLocation;
//
// // A default location (Sydney, Australia) and default zoom to use when location permission is
// // not granted.
// private final LatLng mDefaultLocation = new LatLng(-33.8523341, 151.2106085);
// private static final int DEFAULT_ZOOM = 15;
// private static final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1;
// private boolean mLocationPermissionGranted;
//
// // Used for selecting the current place.
// private static final int M_MAX_ENTRIES = 5;
// private String[] mLikelyPlaceNames;
// private String[] mLikelyPlaceAddresses;
// private String[] mLikelyPlaceAttributions;
// private LatLng[] mLikelyPlaceLatLngs;
// //ImageView back;
// Activity context;
// private FirebaseFirestore db;
// ArrayList<PlaceModel> list = new ArrayList<>();
//
// CheckLocation() {
// db = FirebaseFirestore.getInstance();
// context = getActivity();
//
// }
//
// public void getPlaces(String apiKey){
// com.google.android.libraries.places.api.Places.initialize(context, apiKey);
// mPlacesClient = Places.createClient(context);
// mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context);
// }
//
// private void getCurrentPlaceLikelihoods() {
// // Use fields to define the data types to return.
// List<Place.Field> placeFields = Arrays.asList(Place.Field.NAME, Place.Field.ADDRESS,
// Place.Field.LAT_LNG);
//
// // Get the likely places - that is, the businesses and other points of interest that
// // are the best match for the device's current location.
// @SuppressWarnings("MissingPermission") final FindCurrentPlaceRequest request =
// FindCurrentPlaceRequest.builder(placeFields).build();
// if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// // TODO: Consider calling
// // ActivityCompat#requestPermissions
// // here to request the missing permissions, and then overriding
// // public void onRequestPermissionsResult(int requestCode, String[] permissions,
// // int[] grantResults)
// // to handle the case where the user grants the permission. See the documentation
// // for ActivityCompat#requestPermissions for more details.
// return;
// }
// Task<FindCurrentPlaceResponse> placeResponse = mPlacesClient.findCurrentPlace(request);
// placeResponse.addOnCompleteListener((Executor) this,
// new OnCompleteListener<FindCurrentPlaceResponse>() {
// @Override
// public void onComplete(@NonNull Task<FindCurrentPlaceResponse> task) {
// if (task.isSuccessful()) {
// FindCurrentPlaceResponse response = task.getResult();
// // Set the count, handling cases where less than 5 entries are returned.
// int count;
// if (response.getPlaceLikelihoods().size() < M_MAX_ENTRIES) {
// count = response.getPlaceLikelihoods().size();
// } else {
// count = M_MAX_ENTRIES;
// }
//
// int i = 0;
// mLikelyPlaceNames = new String[count];
// mLikelyPlaceAddresses = new String[count];
// mLikelyPlaceAttributions = new String[count];
// mLikelyPlaceLatLngs = new LatLng[count];
//
// for (PlaceLikelihood placeLikelihood : response.getPlaceLikelihoods()) {
// Place currPlace = placeLikelihood.getPlace();
// mLikelyPlaceNames[i] = currPlace.getName();
// mLikelyPlaceAddresses[i] = currPlace.getAddress();
// mLikelyPlaceAttributions[i] = (currPlace.getAttributions() == null) ?
// null : TextUtils.join(" ", currPlace.getAttributions());
// mLikelyPlaceLatLngs[i] = currPlace.getLatLng();
//
// String currLatLng = (mLikelyPlaceLatLngs[i] == null) ?
// "" : mLikelyPlaceLatLngs[i].toString();
//
//// Log.i(TAG, String.format("Place " + currPlace.getName()
//// + " has likelihood: " + placeLikelihood.getLikelihood()
//// + " at " + currLatLng));
//
// i++;
// if (i > (count - 1)) {
// break;
// }
// int finalI=i;
// CollectionReference placeDB = db.collection("Places");
// String name=currPlace.getName();
// String location=currPlace.getAddress();
// LatLng latLngs=currPlace.getLatLng();
//
// PlaceModel place=new PlaceModel(latLngs,name,location);
// String docIDGen=latLngs.toString();
// int start = docIDGen.indexOf("(");
// int end = docIDGen.indexOf(")");
// int mid = docIDGen.indexOf(",");
// String outStr = docIDGen.substring(start + 1, end);
// int a=0;
// db.collection("Places").document(outStr)
// .set(place)
// .addOnSuccessListener(new OnSuccessListener<Void>() {
// @Override
// public void onSuccess(Void aVoid) {
// //Log.d(TAG, "DocumentSnapshot successfully written!");
// }
// })
// .addOnFailureListener(new OnFailureListener() {
// @Override
// public void onFailure(@NonNull Exception e) {
// //Log.w(TAG, "Error writing document", e);
// }
// });
//
//
// }
//
//
//
// // COMMENTED OUT UNTIL WE DEFINE THE METHOD
// // Populate the ListView
// //fillPlacesList();
// } else {
// Exception exception = task.getException();
// if (exception instanceof ApiException) {
// ApiException apiException = (ApiException) exception;
// //Log.e(TAG, "Place not found: " + apiException.getStatusCode());
// }
// }
// }
// });
// }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment