I know how to get the current location longitude and latitude and save it in Geofire, but how can I get the longitude and latitude of a specific address and save that instead. I test the code below but nothing is being saved.
What am I doing wrong?
String tx7=txt7.getText().toString();
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference().child("locals");
DatabaseReference update = rootRef.child("Users").child(uid);
GeoFire geoFire=new GeoFire(rootRef);
Geocoder geocoder = new Geocoder(AfterRegistrationActivity.this, Locale.getDefault());
String result = null;
List<Address> addressList= null;
try {
addressList = geocoder.getFromLocationName(tx7, 1);
Double latt=addressList.get(0).getLatitude();
Double lonn=addressList.get(0).getLongitude();
geoFire.setLocation(uid, new GeoLocation(latt, lonn), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
if (error != null) {
System.err.println("There was an error saving the location to GeoFire: " + error);
} else {
System.out.println("Location saved on server successfully!");
}
}
});
} catch (IOException e) {
e.printStackTrace();
}