我正在使用实现'uk.co.mgbramwell.geofire:geofire-android:0.0.2'库
主要活动
我使用了实现'uk.co.mgbramwell.geofire:geofire-android:0.0.2'库来设置位置和获取位置
public class MainActivity extends AppCompatActivity implements SetLocationListener {
private static final String TAG = "MainActivity";
private EditText mname,mstate,mlatitude,mlongtitude;
private Button madd,mset;
private String uid;
private Double la,lo;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference myCollection = db.collection("user");
private GeoFire geoFire = new GeoFire(myCollection);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mname = findViewById(R.id.text_name);
mstate = findViewById(R.id.text_state);
mlatitude = findViewById(R.id.text_latitude);
mlongtitude = findViewById(R.id.text_longtitude);
madd = findViewById(R.id.btn_add);
mset = findViewById(R.id.btn_set);
madd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adduser();
}
});
mset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
private void adduser()
{
la= Double.valueOf(mlatitude.getText().toString());
lo= Double.valueOf(mlongtitude.getText().toString());
final User u = new User(mname.getText().toString().trim(), mstate.getText().toString().trim(),la,lo);
db.collection("users")
.add(u)
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()+""+u.getLongtitude()+""+u.getLatitude());
geoFire.setLocation(documentReference.getId(),u.getLatitude(),u.getLongtitude(), MainActivity.this);
Intent intent = new Intent(MainActivity.this,UserlistActivity.class);
startActivity(intent);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error adding document", e);
}
});
}
@Override
public void onCompleted(Exception exception) {
}
}
Gradle
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:17.1.2'
// implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.android.gms:play-services:10.2.0'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'uk.co.mgbramwell.geofire:geofire-android:0.0.2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
implementation 'com.xwray:groupie:2.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.firebase:firebase-auth:16.0.5'
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'
清单
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".UserlistActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
当我调用geofire.setlocation时,它将给出致命的信号错误11并在一段时间内给出
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.geofirecollection, PID: 31334
java.lang.BootstrapMethodError: Exception from call site #0 bootstrap method
错误,请提出一些建议