GeoFire SetLocation不工作

时间:2018-06-04 19:18:57

标签: android firebase firebase-realtime-database geofire

我正在尝试将位置保存到地理位置,但没有从控制台和日志中获得任何响应。

我在gradle文件中添加了依赖项并创建了我的数据库引用,如下所示:

AppConstants.PICK_UP_REF

,字符串PickUpRef等于Log.d(TAG, "UID in PUR:\t" + uid); GeoFire mGeoFire = new GeoFire(pickupRef.child(uid)); if (mLastLocation != null) { mGeoFire.setLocation(uid, new GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()), new GeoFire.CompletionListener() { @Override public void onComplete(String key, DatabaseError error) { if (error != null){ Log.d(TAG, "Write complete"); } else { Log.d(TAG, "Write Failed:\t" + error.getMessage()); } } }); 。在我的活动中,我做到了这一点:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.jjoey.transportr"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
        "android.support.test.runner.AndroidJUnitRunner"
    }
     buildTypes {
         release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
    }
 }

 dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'  
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.reginald:editspinner:1.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'de.hdodenhof:circleimageview:2.1.0'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.google.firebase:firebase-core:12.0.1'
    implementation 'com.google.firebase:firebase-auth:12.0.1'
    implementation 'com.google.firebase:firebase-database:12.0.1'
    implementation 'com.google.firebase:firebase-storage:12.0.1'
    implementation 'com.firebase:geofire-android:2.3.1'
    implementation 'com.google.android.gms:play-services-nearby:12.0.1'
    implementation 'com.google.android.gms:play-services-maps:12.0.1'
    implementation 'com.google.android.gms:play-services-places:12.0.1'
    implementation 'com.google.android.gms:play-services-location:12.0.1'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:cardview-v7:27.1.1'
}
apply plugin: 'com.google.gms.google-services'

oncompletionlistener永远不会被解雇,我的数据库中没有任何更新。还有其他人遇到过这个问题,还是我错误配置了它?

这是我的gradle文件:

{{1}}

1 个答案:

答案 0 :(得分:1)

在app grandle中更改您的依赖关系:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.reginald:editspinner:1.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.firebase:geofire-android:2.3.1'
    implementation 'com.google.android.gms:play-services-nearby:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-places:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:cardview-v7:27.1.1'
}

改变Project grandle:

classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.1'