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

Commit a308bd2

Browse files
authored
Merge pull request #24 from firebase/geofire-2
Geofire 2.0.0
2 parents 5ce3d91 + 0a0fecb commit a308bd2

14 files changed

Lines changed: 272 additions & 70 deletions

File tree

README.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Android app in this repo.
2121

2222
### Integrating GeoFire with your data
2323

24-
GeoFire is designed as a lightweight add-on to Firebase. However, to keep things
24+
GeoFire is designed as a lightweight add-on to the Firebase Realtime Database. However, to keep things
2525
simple, GeoFire stores data in its own format and its own location within
2626
your Firebase database. This allows your existing data format and security rules to
2727
remain unchanged and for you to add GeoFire as an easy solution for geo queries
@@ -41,6 +41,10 @@ at `/bars/<bar-id>`.
4141

4242
## Upgrading GeoFire
4343

44+
### Upgrading from GeoFire 1.x to 2.x
45+
46+
GeoFire 2.0.0 is based on the new 3.x release of [Firebase](https://firebase.google.com).
47+
4448
### Upgrading from GeoFire 1.0.x to 1.1.x
4549

4650
With the release of GeoFire for Android/Java 1.1.0, this library now uses [the new query
@@ -53,31 +57,32 @@ and [read our docs for more information about indexing your data](https://www.fi
5357

5458
## Including GeoFire in your project Android/Java
5559

56-
In order to use GeoFire in your project, you need to [add the Firebase Java
57-
SDK](https://www.firebase.com/docs/java-quickstart.html?utm_source=geofire-java).
58-
There are then multiple possibilities to use GeoFire in your project.
60+
In order to use GeoFire in your project, you need to [add the Firebase Android
61+
SDK](https://firebase.google.com/docs/android/setup). After that you can include
62+
GeoFire with one of the choices below.
63+
64+
### Gradle
65+
66+
Add a dependency for GeoFire to your `gradle.build` file:
67+
68+
```groovy
69+
dependencies {
70+
compile 'com.firebase:geofire:2.0.0'
71+
}
72+
```
5973

6074
### Maven
6175

62-
Add GeoFire to your Maven enabled projects with a new dependency:
76+
GeoFire also works with Maven:
6377

6478
```xml
6579
<dependency>
6680
<groupId>com.firebase</groupId>
6781
<artifactId>geofire</artifactId>
68-
<version>[1.1.0,)</version>
82+
<version>2.0.0</version>
6983
</dependency>
7084
```
7185

72-
### Gradle
73-
74-
Likewise, you can add a dependency to your `gradle.build` file:
75-
76-
```groovy
77-
dependencies {
78-
compile 'com.firebase:geofire:1.1.0+'
79-
}
80-
```
8186

8287
### Jar-File
8388

@@ -88,7 +93,7 @@ page](https://github.com/firebase/geofire-java/releases).
8893
## Getting Started with Firebase
8994

9095
GeoFire requires the Firebase database in order to store location data. You can [sign up here for a free
91-
account](https://www.firebase.com/signup/?utm_source=geofire-java).
96+
account](https://console.firebase.google.com/).
9297

9398

9499
## Quickstart
@@ -103,7 +108,8 @@ database and to create queries. To create a new `GeoFire` instance you need to a
103108
reference.
104109

105110
```java
106-
GeoFire geoFire = new GeoFire(new Firebase("https://<your-firebase>.firebaseio.com/"));
111+
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("path/to/geofire");
112+
GeoFire geoFire = new GeoFire(ref);
107113
```
108114

109115
Note that you can point your reference to anywhere in your Firebase database, but don't
@@ -158,8 +164,8 @@ geoFire.getLocation("firebase-hq", new LocationCallback() {
158164
}
159165

160166
@Override
161-
public void onCancelled(FirebaseError firebaseError) {
162-
System.err.println("There was an error getting the GeoFire location: " + firebaseError);
167+
public void onCancelled(DatabaseError databaseError) {
168+
System.err.println("There was an error getting the GeoFire location: " + databaseError);
163169
}
164170
});
165171
```
@@ -229,7 +235,7 @@ geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
229235
}
230236

231237
@Override
232-
public void onGeoQueryError(FirebaseError error) {
238+
public void onGeoQueryError(DatabaseError error) {
233239
System.err.println("There was an error with this query: " + error);
234240
}
235241
});

android/pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<!-- Inherit from ../pom.xml -->
6+
<parent>
7+
<groupId>com.firebase</groupId>
8+
<artifactId>geofire</artifactId>
9+
<version>2.0.0-SNAPSHOT</version>
10+
<relativePath>../</relativePath>
11+
</parent>
12+
13+
<artifactId>geofire-android</artifactId>
14+
<packaging>aar</packaging>
15+
16+
<name>geofire-android</name>
17+
<description>GeoFire is an open-source library for Android/Java that allows you to store and query a set of keys based on their geographic location.</description>
18+
<organization>
19+
<name>Firebase</name>
20+
<url>https://www.firebase.com/</url>
21+
</organization>
22+
<url>https://github.com/firebase/geofire-java</url>
23+
<scm>
24+
<connection>scm:git:git@github.com:firebase/geofire-java.git</connection>
25+
<developerConnection>scm:git:git@github.com:firebase/geofire-java.git</developerConnection>
26+
<url>https://github.com/firebase/geofire-java</url>
27+
</scm>
28+
<licenses>
29+
<license>
30+
<name>MIT</name>
31+
<url>http://firebase.mit-license.org</url>
32+
</license>
33+
</licenses>
34+
<properties>
35+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36+
</properties>
37+
<build>
38+
<sourceDirectory>../src/main/java</sourceDirectory>
39+
<plugins>
40+
<plugin>
41+
<groupId>com.simpligility.maven.plugins</groupId>
42+
<artifactId>android-maven-plugin</artifactId>
43+
<version>4.3.0</version> <!-- use latest release -->
44+
<extensions>true</extensions>
45+
</plugin>
46+
</plugins>
47+
</build>
48+
<repositories>
49+
<repository>
50+
<id>google-extras</id>
51+
<url>file://${env.ANDROID_HOME}/extras/google/m2repository</url>
52+
</repository>
53+
<repository>
54+
<id>android-extras</id>
55+
<url>file://${env.ANDROID_HOME}/extras/android/m2repository</url>
56+
</repository>
57+
</repositories>
58+
<dependencies>
59+
<dependency>
60+
<groupId>com.google.firebase</groupId>
61+
<artifactId>firebase-database</artifactId>
62+
<version>[9.0.2,)</version>
63+
<scope>provided</scope>
64+
<type>aar</type>
65+
</dependency>
66+
<dependency>
67+
<groupId>com.google.android</groupId>
68+
<artifactId>android</artifactId>
69+
<version>2.2.1</version>
70+
<scope>provided</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>junit</groupId>
74+
<artifactId>junit</artifactId>
75+
<version>4.8.1</version>
76+
<scope>test</scope>
77+
</dependency>
78+
</dependencies>
79+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.firebase.geofire">
2+
<uses-sdk
3+
android:minSdkVersion="9"
4+
android:targetSdkVersion="24" />
5+
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
</manifest>

examples/SFVehicles/SF Vehicles/build.gradle

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
mavenCentral()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:1.0.0'
6+
classpath 'com.android.tools.build:gradle:2.1.0'
77
}
88
}
99
apply plugin: 'com.android.application'
@@ -14,12 +14,13 @@ repositories {
1414
}
1515

1616
android {
17-
compileSdkVersion 20
18-
buildToolsVersion "21.1.1"
17+
compileSdkVersion 23
18+
buildToolsVersion "23.0.3"
1919

2020
defaultConfig {
21+
applicationId 'com.firebase.sfvehicles'
2122
minSdkVersion 9
22-
targetSdkVersion 20
23+
targetSdkVersion 23
2324
versionCode 1
2425
versionName "1.0"
2526
}
@@ -38,14 +39,16 @@ android {
3839
dependencies {
3940
compile fileTree(dir: 'libs', include: ['*.jar'])
4041
// You must install or update the Support Repository through the SDK manager to use this dependency.
41-
compile 'com.android.support:support-v4:20.+'
42+
compile 'com.android.support:support-v4:23.4.0'
4243
// You must install or update the Support Repository through the SDK manager to use this dependency.
43-
compile 'com.android.support:appcompat-v7:20.+'
44+
compile 'com.android.support:appcompat-v7:23.4.0'
45+
// You must install or update the Support Repository through the SDK manager to use this dependency.
46+
compile 'com.google.android.gms:play-services-maps:9.0.2'
4447
// You must install or update the Google Repository through the SDK manager to use this dependency.
45-
compile 'com.google.android.gms:play-services:6.1.+'
46-
// Firebase
47-
compile 'com.firebase:firebase-client-android:2.0.+'
48+
compile 'com.google.firebase:firebase-core:9.0.2'
49+
compile 'com.google.firebase:firebase-database:9.0.2'
50+
4851
// GeoFire
49-
compile 'com.firebase:geofire:1.1.+'
52+
compile 'com.firebase:geofire:2.0.0'
5053
}
5154

examples/SFVehicles/SF Vehicles/src/main/java/com/firebase/sfvehicles/SFVehiclesActivity.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import android.support.v4.app.FragmentActivity;
99
import android.view.animation.AccelerateDecelerateInterpolator;
1010
import android.view.animation.Interpolator;
11-
import com.firebase.client.Firebase;
12-
import com.firebase.client.FirebaseError;
1311
import com.firebase.geofire.GeoFire;
1412
import com.firebase.geofire.GeoLocation;
1513
import com.firebase.geofire.GeoQuery;
@@ -18,6 +16,10 @@
1816
import com.google.android.gms.maps.GoogleMap;
1917
import com.google.android.gms.maps.SupportMapFragment;
2018
import com.google.android.gms.maps.model.*;
19+
import com.google.firebase.FirebaseApp;
20+
import com.google.firebase.FirebaseOptions;
21+
import com.google.firebase.database.DatabaseError;
22+
import com.google.firebase.database.FirebaseDatabase;
2123

2224
import java.util.HashMap;
2325
import java.util.Map;
@@ -26,7 +28,8 @@ public class SFVehiclesActivity extends FragmentActivity implements GeoQueryEven
2628

2729
private static final GeoLocation INITIAL_CENTER = new GeoLocation(37.7789, -122.4017);
2830
private static final int INITIAL_ZOOM_LEVEL = 14;
29-
private static final String GEO_FIRE_REF = "https://publicdata-transit.firebaseio.com/_geofire";
31+
private static final String GEO_FIRE_DB = "https://publicdata-transit.firebaseio.com";
32+
private static final String GEO_FIRE_REF = GEO_FIRE_DB + "/_geofire";
3033

3134
private GoogleMap map;
3235
private Circle searchCircle;
@@ -50,10 +53,11 @@ protected void onCreate(Bundle savedInstanceState) {
5053
this.map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngCenter, INITIAL_ZOOM_LEVEL));
5154
this.map.setOnCameraChangeListener(this);
5255

53-
Firebase.setAndroidContext(this);
56+
FirebaseOptions options = new FirebaseOptions.Builder().setApplicationId("geofire").setDatabaseUrl(GEO_FIRE_DB).build();
57+
FirebaseApp app = FirebaseApp.initializeApp(this, options);
5458

5559
// setup GeoFire
56-
this.geoFire = new GeoFire(new Firebase(GEO_FIRE_REF));
60+
this.geoFire = new GeoFire(FirebaseDatabase.getInstance(app).getReferenceFromUrl(GEO_FIRE_REF));
5761
// radius in km
5862
this.geoQuery = this.geoFire.queryAtLocation(INITIAL_CENTER, 1);
5963

@@ -110,7 +114,7 @@ public void onGeoQueryReady() {
110114
}
111115

112116
@Override
113-
public void onGeoQueryError(FirebaseError error) {
117+
public void onGeoQueryError(DatabaseError error) {
114118
new AlertDialog.Builder(this)
115119
.setTitle("Error")
116120
.setMessage("There was an unexpected error querying GeoFire: " + error.getMessage())

examples/SFVehicles/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.0.0'
8+
classpath 'com.android.tools.build:gradle:2.1.0'
99
}
1010
}
1111

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Dec 18 13:18:37 PST 2014
1+
#Wed Jun 08 11:39:36 PDT 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

java/pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<!-- Inherit from ../pom.xml -->
6+
<parent>
7+
<groupId>com.firebase</groupId>
8+
<artifactId>geofire</artifactId>
9+
<version>2.0.0-SNAPSHOT</version>
10+
<relativePath>../</relativePath>
11+
</parent>
12+
13+
<artifactId>geofire-java</artifactId>
14+
<packaging>jar</packaging>
15+
16+
<name>geofire-java</name>
17+
<description>GeoFire is an open-source library for Android/Java that allows you to store and query a set of keys based on their geographic location.</description>
18+
<organization>
19+
<name>Firebase</name>
20+
<url>https://www.firebase.com/</url>
21+
</organization>
22+
<url>https://github.com/firebase/geofire-java</url>
23+
<scm>
24+
<connection>scm:git:git@github.com:firebase/geofire-java.git</connection>
25+
<developerConnection>scm:git:git@github.com:firebase/geofire-java.git</developerConnection>
26+
<url>https://github.com/firebase/geofire-java</url>
27+
</scm>
28+
<licenses>
29+
<license>
30+
<name>MIT</name>
31+
<url>http://firebase.mit-license.org</url>
32+
</license>
33+
</licenses>
34+
<properties>
35+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36+
</properties>
37+
<build>
38+
<!-- Plugins inherited -->
39+
</build>
40+
<dependencies>
41+
<dependency>
42+
<groupId>com.google.firebase</groupId>
43+
<artifactId>firebase-server-sdk</artifactId>
44+
<version>[3.0.0,)</version>
45+
<scope>provided</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.google.android</groupId>
49+
<artifactId>android</artifactId>
50+
<version>2.2.1</version>
51+
<scope>provided</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>junit</groupId>
55+
<artifactId>junit</artifactId>
56+
<version>4.8.1</version>
57+
<scope>test</scope>
58+
</dependency>
59+
</dependencies>
60+
</project>

0 commit comments

Comments
 (0)