Skip to content
Snippets Groups Projects
Commit 683d6624 authored by kishoreraju2's avatar kishoreraju2
Browse files

GPS Bug fixed

parent f465de6a
Branches master
No related tags found
No related merge requests found
...@@ -54,6 +54,9 @@ import static android.app.Activity.RESULT_OK; ...@@ -54,6 +54,9 @@ import static android.app.Activity.RESULT_OK;
public class CameraFragment extends Fragment { public class CameraFragment extends Fragment {
String UserEmail = null;
final DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference("users");
private static final String IMAGE_DIRECTORY_NAME = "Hello_Camera"; private static final String IMAGE_DIRECTORY_NAME = "Hello_Camera";
View view; View view;
private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100; private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100;
...@@ -94,6 +97,7 @@ public class CameraFragment extends Fragment { ...@@ -94,6 +97,7 @@ public class CameraFragment extends Fragment {
firebaseUser = firebaseAuth.getCurrentUser(); firebaseUser = firebaseAuth.getCurrentUser();
UID = firebaseUser.getUid(); UID = firebaseUser.getUid();
final String data = firebaseAuth.getCurrentUser().getEmail();
mStorageRef = FirebaseStorage.getInstance().getReference(); mStorageRef = FirebaseStorage.getInstance().getReference();
btnCapturePicture = (Button) view.findViewById(R.id.btnCapturePicture); btnCapturePicture = (Button) view.findViewById(R.id.btnCapturePicture);
...@@ -152,7 +156,7 @@ public class CameraFragment extends Fragment { ...@@ -152,7 +156,7 @@ public class CameraFragment extends Fragment {
} }
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, final Intent data) {
// if the result is capturing Image // if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) { if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
...@@ -167,7 +171,35 @@ public class CameraFragment extends Fragment { ...@@ -167,7 +171,35 @@ public class CameraFragment extends Fragment {
latitude = gps .getLatitude(); latitude = gps .getLatitude();
city = gps.getCity(); city = gps.getCity();
postalCode = gps.getPostalCode(); postalCode = gps.getPostalCode();
Toast.makeText(getActivity(),"Longitude:"+Double.toString(longitude)+"\nLatitude:"+Double.toString(latitude)+"\nCity:"+city+"\nPostal:"+postalCode,Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), city, Toast.LENGTH_SHORT).show();
/* mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
UserEmail = snapshot.child("email").toString().split("value =")[1].split(" ")[1].replaceAll("\\s+","");
if(UserEmail.equals(data)) {
snapshot.getRef().child("location").setValue(city);
Toast.makeText(getActivity(), UserEmail, Toast.LENGTH_SHORT).show();
Log.e("Location:",city);
break;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});*/
// Toast.makeText(getActivity(),"Longitude:"+Double.toString(longitude)+"\nLatitude:"+Double.toString(latitude)+"\nCity:"+city+"\nPostal:"+postalCode,Toast.LENGTH_SHORT).show();
} }
else else
{ {
......
...@@ -123,6 +123,35 @@ public class TrackGPS extends Service implements LocationListener { ...@@ -123,6 +123,35 @@ public class TrackGPS extends Service implements LocationListener {
//String country = addresses.get(0).getCountryName(); //String country = addresses.get(0).getCountryName();
postalCode = addresses.get(0).getPostalCode(); postalCode = addresses.get(0).getPostalCode();
//String knownName = addresses.get(0).getFeatureName(); //String knownName = addresses.get(0).getFeatureName();
// addresses = geocoder.getFromLocation(latitude, longitude, 1);
// String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
// city = addresses.get(0).getLocality();
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
UserEmail = snapshot.child("email").toString().split("value =")[1].split(" ")[1].replaceAll("\\s+","");
if(UserEmail.equals(data)) {
snapshot.getRef().child("location").setValue(city);
Log.e("Location:",city);
break;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} }
} }
catch(SecurityException e){ catch(SecurityException e){
...@@ -145,6 +174,7 @@ public class TrackGPS extends Service implements LocationListener { ...@@ -145,6 +174,7 @@ public class TrackGPS extends Service implements LocationListener {
longitude = loc.getLongitude(); longitude = loc.getLongitude();
Geocoder geocoder= new Geocoder(mContext,Locale.getDefault()); Geocoder geocoder= new Geocoder(mContext,Locale.getDefault());
List<Address> addresses; List<Address> addresses;
int flags = 0;
addresses = geocoder.getFromLocation(latitude, longitude, 1); addresses = geocoder.getFromLocation(latitude, longitude, 1);
// String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex() // String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
...@@ -158,10 +188,15 @@ public class TrackGPS extends Service implements LocationListener { ...@@ -158,10 +188,15 @@ public class TrackGPS extends Service implements LocationListener {
if(UserEmail.equals(data)) { if(UserEmail.equals(data)) {
snapshot.getRef().child("location").setValue(city); snapshot.getRef().child("location").setValue(city);
Log.e("Location:",city);
break; break;
} }
} }
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment