Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Close #134 #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions common/src/main/java/com/firebase/geofire/GeoFire.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,35 @@ public void onComplete(DatabaseError databaseError, DatabaseReference databaseRe
}
}

/**
* Update the location for a given key.
*
* @param key The key to save the location for
* @param location The location of this key
* @param completionListener A listener that is called once the location was successfully saved on the server or an
* error occurred
*/
public void updateLocation(final String key, final GeoLocation location, final CompletionListener completionListener){
if (key == null) {
throw new NullPointerException();
}
DatabaseReference keyRef = this.getDatabaseRefForKey(key);
GeoHash geoHash = new GeoHash(location);
Map<String, Object> updates = new HashMap<>();
updates.put("g", geoHash.getGeoHashString());
updates.put("l", Arrays.asList(location.latitude, location.longitude));
if (completionListener != null) {
keyRef.updateChildren(updates, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
completionListener.onComplete(key, databaseError);
}
});
} else {
keyRef.updateChildren(updates);
}
}

/**
* Removes the location for a key from this GeoFire.
*
Expand Down