【问题标题】:GeoFire SetLocation Not WorkingGeoFire SetLocation 不工作
【发布时间】:2018-11-14 04:36:13
【问题描述】:

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

我在 gradle 文件中添加了依赖项,并像这样创建了我的数据库引用:

    DatabaseReference pickupRef = FirebaseDatabase.getInstance().getReference(AppConstants.PICK_UP_REF);
    pickupRef.keepSynced(true);

并且字符串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());
                }
            }
        });

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

这是我的 gradle 文件:

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'

【问题讨论】:

  • 可能不相关,但您的“onComplete”逻辑是向后的 - 您检查“not null”,因此如果它为 null,则尝试访问错误。所以换句话说,如果它成功了,你会得到一个空指针异常。
  • @Andromeda 请也添加大文件,谢谢
  • @Andy,来自 geofire 文档
  • @ParaskevasNtsounos,再次检查
  • @Andromeda 检查我的答案并告诉我发生了什么

标签: android firebase firebase-realtime-database geofire


【解决方案1】:

在应用程序中更改您的依赖项,如下所示:

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'

【讨论】:

  • 它正在工作,我意识到由于变量名称错误,设置的值是空的。我会接受你的回答,尽管没有其他人尝试过帮忙。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多