这是代码,单击“提交”按钮填充并提交输入字段后,就会运行该代码,我在下面收到错误消息
package com.manavchordia.aplparent;
import androidx.fragment.app.FragmentActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.database.annotations.NotNull;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, View.OnClickListener {
private GoogleMap mMap;
private FirebaseAuth mAuth;
//String value_latitude = "0";
// String value_longitue = "0";
Double longi = 0.0;
Double lati = 0.0;
// String message = "BUS1";
Button Refreshh;
Double latitude = 0.0;
Double longitude = 0.0;
String vali;
Button Backp;
TextView BusNO;
private CountDownTimer timer;
private FirebaseDatabase mDatabase = FirebaseDatabase.getInstance();
private DatabaseReference myRef = mDatabase.getReference().child("Locations").child(vali);
// private DatabaseReference mDatabaseReference = mDatabase.getReference();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
Backp = findViewById(R.id.backbuttonmap);
BusNO = findViewById(R.id.busnotext);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String str = bundle.getString("message");
vali = str;
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
BusNO.setText(vali);
timer = new CountDownTimer(5000, 500) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
try {
timer.start();
Toast.makeText(MapsActivity.this, "Refreshing", Toast.LENGTH_LONG).show();
getBussGeo();
} catch (Exception e) {
Log.e("Error", "Error: " + e.toString());
}
}
}.start();
Backp.setOnClickListener(this);
Backp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MapsActivity.this, MainActivity.class);
timer.cancel();
startActivity(intent);
}
});
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
/*
if (mMap != null) {
LatLng sydney = new LatLng(lati, longi);
mMap.addMarker(new MarkerOptions().position(sydney).title(vali));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
*/
}
public void getBussGeo() {
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NotNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
double latitude = dataSnapshot.child("latitude").getValue(Double.class);
double longitude = dataSnapshot.child("longitude").getValue(Double.class);
Log.e("Long", "onDataChange: " + longitude);
Log.d("lato","onDataChange" + latitude);
lati = latitude;
longi = longitude;
if (mMap != null) {
LatLng sydney = new LatLng(lati, longi);
mMap.addMarker(new MarkerOptions().position(sydney).title(vali));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
}
@Override
public void onCancelled(@NotNull DatabaseError error) {
// Failed to read value
Toast.makeText(getApplicationContext(), "Error!!", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onClick(View view) {
}
}
错误:
无法加载localhost:1337 / firstc / list:跨源请求仅支持以下协议方案:http,数据,chrome,chrome扩展名,https。