diff --git a/common/src/main/java/com/firebase/geofire/GeoFire.java b/common/src/main/java/com/firebase/geofire/GeoFire.java index 1d0f20f..19b8bf5 100644 --- a/common/src/main/java/com/firebase/geofire/GeoFire.java +++ b/common/src/main/java/com/firebase/geofire/GeoFire.java @@ -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 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. *