Search in sources :

Example 1 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project firebase-android-sdk by firebase.

the class ValuesTest method testCanonicalIds.

@Test
public void testCanonicalIds() {
    assertCanonicalId(TestUtil.wrap(null), "null");
    assertCanonicalId(TestUtil.wrap(true), "true");
    assertCanonicalId(TestUtil.wrap(false), "false");
    assertCanonicalId(TestUtil.wrap(1), "1");
    assertCanonicalId(TestUtil.wrap(1.0), "1.0");
    assertCanonicalId(TestUtil.wrap(new Timestamp(30, 1000)), "time(30,1000)");
    assertCanonicalId(TestUtil.wrap("a"), "a");
    assertCanonicalId(TestUtil.wrap(blob(1, 2, 3)), "010203");
    assertCanonicalId(wrapRef(dbId("p1", "d1"), key("c1/doc1")), "c1/doc1");
    assertCanonicalId(TestUtil.wrap(new GeoPoint(30, 60)), "geo(30.0,60.0)");
    assertCanonicalId(TestUtil.wrap(Arrays.asList(1, 2, 3)), "[1,2,3]");
    assertCanonicalId(TestUtil.wrap(map("a", 1, "b", 2, "c", "3")), "{a:1,b:2,c:3}");
    assertCanonicalId(TestUtil.wrap(map("a", Arrays.asList("b", map("c", new GeoPoint(30, 60))))), "{a:[b,{c:geo(30.0,60.0)}]}");
}
Also used : GeoPoint(com.google.firebase.firestore.GeoPoint) Timestamp(com.google.firebase.Timestamp) Test(org.junit.Test)

Example 2 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project firebase-android-sdk by firebase.

the class ValuesTest method testValueEquality.

@Test
public void testValueEquality() {
    GeoPoint geoPoint1 = new GeoPoint(1, 0);
    GeoPoint geoPoint2 = new GeoPoint(0, 2);
    Timestamp timestamp1 = new Timestamp(date1);
    Timestamp timestamp2 = new Timestamp(date2);
    new EqualsTester().addEqualityGroup(wrap(true), wrap(true)).addEqualityGroup(wrap(false), wrap(false)).addEqualityGroup(wrap((Object) null), wrap(Values.NULL_VALUE)).addEqualityGroup(wrap(0.0 / 0.0), wrap(Double.longBitsToDouble(0x7ff8000000000000L)), wrap(Values.NAN_VALUE)).addEqualityGroup(wrap(-0.0)).addEqualityGroup(wrap(0.0)).addEqualityGroup(wrap(1), wrap(1)).addEqualityGroup(wrap(1.0), wrap(1.0)).addEqualityGroup(wrap(1.1), wrap(1.1)).addEqualityGroup(wrap(blob(0, 1, 2)), wrap(blob(0, 1, 2))).addEqualityGroup(wrap(blob(0, 1))).addEqualityGroup(wrap("string"), wrap("string")).addEqualityGroup(wrap("strin")).addEqualityGroup(wrap("e\u0301b")).addEqualityGroup(wrap("\u00e9a")).addEqualityGroup(wrap(date1), wrap(timestamp1)).addEqualityGroup(wrap(timestamp2)).addEqualityGroup(wrap(ServerTimestamps.valueOf(new Timestamp(date1), null)), wrap(ServerTimestamps.valueOf(new Timestamp(date1), null))).addEqualityGroup(wrap(ServerTimestamps.valueOf(new Timestamp(date2), null))).addEqualityGroup(wrap(geoPoint1), wrap(new GeoPoint(1, 0))).addEqualityGroup(wrap(geoPoint2)).addEqualityGroup(wrap(ref("coll/doc1")), wrap(wrapRef(dbId("project"), key("coll/doc1")))).addEqualityGroup(wrap(wrapRef(dbId("project", "bar"), key("coll/doc2")))).addEqualityGroup(wrap(wrapRef(dbId("project", "baz"), key("coll/doc2")))).addEqualityGroup(wrap(Arrays.asList("foo", "bar")), wrap(Arrays.asList("foo", "bar"))).addEqualityGroup(wrap(Arrays.asList("foo", "bar", "baz"))).addEqualityGroup(wrap(Arrays.asList("foo"))).addEqualityGroup(wrap(map("bar", 1, "foo", 2)), wrap(map("foo", 2, "bar", 1))).addEqualityGroup(wrap(map("bar", 2, "foo", 1))).addEqualityGroup(wrap(map("bar", 1))).addEqualityGroup(wrap(map("foo", 1))).testEquals();
}
Also used : GeoPoint(com.google.firebase.firestore.GeoPoint) EqualsTester(com.google.common.testing.EqualsTester) Timestamp(com.google.firebase.Timestamp) Test(org.junit.Test)

Example 3 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project turtleparties by CMPUT301W22T21.

the class MapsActivity method addQRMarkers.

public void addQRMarkers(@NonNull GoogleMap googleMap) {
    mMap = googleMap;
    db.collection("QR codes").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot doc : task.getResult()) {
                    String qrname = doc.getId();
                    db.collection("QR codes").document(qrname).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {

                        @Override
                        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                            if (task.isSuccessful()) {
                                DocumentSnapshot doc = task.getResult();
                                Integer score = ((Number) doc.getData().get("score")).intValue();
                                GeoPoint qrGeoPoint = (GeoPoint) doc.getData().get("geolocation");
                                Double latval = 0.0;
                                Double longval = 0.0;
                                try {
                                    latval = qrGeoPoint.getLatitude();
                                    longval = qrGeoPoint.getLongitude();
                                } catch (Exception e) {
                                    Log.d(TAG, "EMPTY GEOPOINT");
                                }
                                Log.d(TAG, latval + "  " + longval + "  " + score);
                                LatLng thisMarker = new LatLng(latval, longval);
                                mMap.addMarker(new MarkerOptions().position(thisMarker).title(String.valueOf(score)));
                            }
                        }
                    });
                }
            } else {
                Log.d(TAG, "Error getting documents: ", task.getException());
            }
        }
    });
}
Also used : Task(com.google.android.gms.tasks.Task) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) WriterException(com.google.zxing.WriterException) FirebaseFirestoreException(com.google.firebase.firestore.FirebaseFirestoreException) GeoPoint(com.google.firebase.firestore.GeoPoint) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) NonNull(androidx.annotation.NonNull) LatLng(com.google.android.gms.maps.model.LatLng)

Example 4 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project turtleparties by CMPUT301W22T21.

the class QRCodesTest method checkHasGeoPoint.

@Test
public void checkHasGeoPoint() {
    GeoPoint gp = new GeoPoint(12, 12);
    testQR.setGeolocation(gp);
    assertTrue(testQR.hasGeoLocation());
}
Also used : GeoPoint(com.google.firebase.firestore.GeoPoint) Test(org.junit.Test)

Example 5 with GeoPoint

use of com.google.firebase.firestore.GeoPoint in project turtleparties by CMPUT301W22T21.

the class QRCodesTest method checkCorrectGeoPointReturned.

@Test
public void checkCorrectGeoPointReturned() {
    GeoPoint gp = new GeoPoint(12, 12);
    testQR.setGeolocation(gp);
    GeoPoint ap = testQR.getGeolocation();
    assertEquals(ap, gp);
}
Also used : GeoPoint(com.google.firebase.firestore.GeoPoint) Test(org.junit.Test)

Aggregations

GeoPoint (com.google.firebase.firestore.GeoPoint)9 Test (org.junit.Test)6 Timestamp (com.google.firebase.Timestamp)4 NonNull (androidx.annotation.NonNull)1 LatLng (com.google.android.gms.maps.model.LatLng)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)1 Task (com.google.android.gms.tasks.Task)1 EqualsTester (com.google.common.testing.EqualsTester)1 Blob (com.google.firebase.firestore.Blob)1 DocumentReference (com.google.firebase.firestore.DocumentReference)1 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)1 FieldValue (com.google.firebase.firestore.FieldValue)1 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)1 ServerTimestamp (com.google.firebase.firestore.ServerTimestamp)1 ObjectValue (com.google.firebase.firestore.model.ObjectValue)1 Values.refValue (com.google.firebase.firestore.model.Values.refValue)1 ArrayValue (com.google.firestore.v1.ArrayValue)1