2
I would like to know how to get the address when the client adds the marker to the map, and already save it to the firebase server. Thanks in advance :)
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng brazil = new LatLng(-18, -48);
mMap.setInfoWindowAdapter(new UserAdapter());
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(brazil, 4));
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
mMap.setOnMapLongClickListener(this);
UiSettings uiSettings = googleMap.getUiSettings();
uiSettings.setCompassEnabled(true);
uiSettings.setZoomControlsEnabled(true);
mDatabase1.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
User childUser = dataSnapshot.getValue(User.class);
LatLng childPos = new LatLng(childUser.getLat(),childUser.getLang());
MarkerOptions markerOptions =new MarkerOptions().position(childPos);
Marker marker = mMap.addMarker(markerOptions);
userMarkers.put(dataSnapshot.getKey(),marker);
userMap.put(dataSnapshot.getKey(),childUser);
}
@Override
public void onChildChanged(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
Location childLocation = dataSnapshot.getValue(Location.class);
Marker oldMarker = userMarkers.get(dataSnapshot.getKey());
oldMarker.remove();
LatLng childPos = new LatLng(childLocation.getLat(),childLocation.getLang());
MarkerOptions markerOptions =new MarkerOptions().position(childPos);
Marker marker = mMap.addMarker(markerOptions);
userMarkers.put(dataSnapshot.getKey(),marker);
userMap.get(dataSnapshot.getKey()).setLat(childLocation.getLat());
userMap.get(dataSnapshot.getKey()).setLang(childLocation.getLang());
//Aqui eu mando para o firebase a possição que foi marcada no mapa
//quero mandar o endereço por aqui
}
@Override
public void onChildRemoved(com.google.firebase.database.DataSnapshot dataSnapshot) {
Marker oldMarker = userMarkers.get(dataSnapshot.getKey());
oldMarker.remove();
userMarkers.remove(dataSnapshot.getKey());
userMap.remove(dataSnapshot.getKey());
//aqui para remover o marcador.
//Aqui pra remover o endereço.
}
@Override
public void onChildMoved(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}});}
@Override
public void onMapLongClick(LatLng latLng) {
Location location=new Location(latLng.latitude,latLng.longitude);
sendMark(location);
}
private void sendMark(Location location){
String userName= FirebaseAuth.getInstance().getCurrentUser().getUid();
mDatabase1.child(userName).child("lat").setValue(location.getLat());
mDatabase1.child(userName).child("lang").setValue(location. getLang());
}
@Override
public void onInfoWindowClick(Marker marker) {
marker.hideInfoWindow();
marker.showInfoWindow();
}