gpt4 book ai didi

android - 我想在实时 FIrebase 中存储纬度和经度....并具有以下代码

转载 作者:行者123 更新时间:2023-11-30 05:03:57 24 4
gpt4 key购买 nike

这是我在android中查看当前位置的纬度和经度的代码。我想在 firebase 中保存位置。我删除了查看位置的代码,从而将位置存储在数据库中。我想将当前位置保存到 firebase 中,稍后再检索。

public class MapsActivity extends AppCompatActivity {

private GoogleMap mMap;
private FusedLocationProviderClient client;
private LatLng lng;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

requestPermission();
client = LocationServices.getFusedLocationProviderClient(this);

Button button = findViewById(R.id.button);
EditText EditText = findViewById(R.id.ed);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ActivityCompat.checkSelfPermission(MapsActivity.this, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
client.getLastLocation().addOnSuccessListener(MapsActivity.this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location!=null)
{


}
}
});
}
});

}
public void requestPermission()
{

ActivityCompat.requestPermissions(this,new String[]{ACCESS_FINE_LOCATION},1);

}

}

最佳答案

首先,注册到firebase Console 并获取JSON 数据,然后您可以指向Database Reference 及其对应的child。

if(location!=null)
{
DatabaseReference mDatabase;
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("Location").child("Lat").setValue(location.latitude);
}

关于android - 我想在实时 FIrebase 中存储纬度和经度....并具有以下代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54902933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com