How do I save latitude and longitude in Firebase?

0

I was told that I have to save as double , but I do not know how to do it, if someone can help me I appreciate:)

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    Marker marker;


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

        // 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);
    }

        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            return;
        }
        googleMap.setMyLocationEnabled(true); //Exibi o botão de localizar a localização do usuário

        mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

            @Override
            public void onMapLongClick(LatLng arg0) {
                if (marker != null) {
                    marker.remove();
                }
                marker = mMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.code_the_road_small))
                        .position(
                                new LatLng(arg0.latitude,
                                        arg0.longitude))
                        .draggable(true).visible(true));
                 }


        });}}

How do I save latitude and longitude in Firebase?

    
asked by anonymous 27.11.2016 / 16:38

1 answer

1

If you want to conduct a radius-based search in the future, I encourage you to use GeoFire .

Example:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("path/to/geofire");
GeoFire geoFire = new GeoFire(ref);

geoFire.setLocation("firebase-hq", new GeoLocation(37.7853889, -122.4056973));

Or you can save a double value, eg:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("path/to/user");
ref.child("latitude").setValue(37.7853889);
ref.child("longitude").setValue(-122.4056973);

Firebase allows you to save data in several ways, I recommend you check their documentation as well and it is in Portuguese.

link

    
17.01.2017 / 14:03