public class Root_Map extends AppCompatActivity implements OnMapReadyCallback {
ArrayList<LatLng> poos;
/*public Root_Map(ArrayList poos) {
this.poos = poos;
}*/
Huerta huerta;
private boolean s = false;
private GoogleMap mMap;
private DatabaseReference database;
private FirebaseDatabase db;
FrameLayout fram_map;
PolygonOptions rectOptions, rectOptio;
ArrayList lon = new ArrayList();
ArrayList lat = new ArrayList();
ArrayList val = new ArrayList();
private ArrayAdapter<String> adapterCat, adapterpol;
Polygon polygon, pa;
Button dib, elim, guar, btn_editarpol;
int i = 0;
HashMap<String, ArrayList> nombremap = new HashMap<String, ArrayList>();
private Spinner hue;
private AdapterMapsHuerta adapter;
private RecyclerView recyclerpo;
Boolean Is_MAP_Moveable = false;
private Poligonoo poligo1;
PopupWindow popupWindow;
public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;
protected LocationManager locationManager;
List<Poligonoo> poligonos = new ArrayList<>();
List<PolygonOptions> pol = new ArrayList<>();
List<Polygon> polos = new ArrayList<>();
List<ArrayList> lala = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.root__map);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// Bordes del polígo
fram_map = findViewById(R.id.fram_map);
hue = findViewById(R.id.sp);
FloatingActionButton fab = findViewById(R.id.fab);
dib = findViewById(R.id.btn_dibujar_map);
elim = findViewById(R.id.btn_eliminar_map);
guar = findViewById(R.id.btn_Guardar_map);
elim.setVisibility(View.INVISIBLE);
guar.setVisibility(View.INVISIBLE);
hue.setVisibility(View.INVISIBLE);
final List<String> huertas = new ArrayList<>();
database = FirebaseDatabase.getInstance().getReference("Huertas");
database.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
huertas.removeAll(huertas);
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
for (DataSnapshot ss : snapshot.getChildren()) {
Huerta huerta = ss.getValue(Huerta.class);
huertas.add(huerta.getNombrePredio());
}
}
adapterCat = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.select_dialog_item, huertas);
hue.setAdapter(adapterCat);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
db = FirebaseDatabase.getInstance();
db.getReference("Poligono").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
poligonos.removeAll(poligonos);
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
//for (DataSnapshot ss : snapshot.getChildren()) {
//for (DataSnapshot ds : ss.getChildren()) {
ArrayList producto = snapshot.getValue(ArrayList.class);
lala.add(producto);
Toast.makeText(Root_Map.this, "producto: " + producto, Toast.LENGTH_SHORT).show();
// }
// }
// Polygon poll=snapshot.getValue(Polygon.class);
//polos.add(poll);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hue.setVisibility(View.VISIBLE);
// Intent intent = new Intent(getBaseContext(), NuevaHuertaMapa.class);
//startActivity(intent);
}
});
guar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Guardarpol((String) hue.getSelectedItem());
dib.setVisibility(View.INVISIBLE);
}
});
}
@Override
public void onMapReady(final GoogleMap googleMap) {
mMap = googleMap;
checkLocationPermission();
LocationServices.getFusedLocationProviderClient(getApplicationContext()).getLastLocation()
.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(),
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;
}
mMap.setMyLocationEnabled(true);
LatLng dgs = new LatLng(location.getLatitude(), location.getLongitude());
mMap.addMarker(new MarkerOptions().position(dgs).title("Tu ubicacion actual :)"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(dgs, 19));
}
});
dib.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dib.setVisibility(View.INVISIBLE);
guar.setVisibility(View.VISIBLE);
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
Toast.makeText(Root_Map.this, "Un solo clic", Toast.LENGTH_SHORT).show();
val.add(latLng);
lat.add(latLng.latitude);
lon.add(latLng.longitude);
Draw_Map();
}
});
}
});
mMap.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
@Override
public void onPolygonClick(Polygon polygon) {
}
});
//Toast.makeText(this, "este es el valor de poos: " +this.poligonos.get(0).getPoo(), Toast.LENGTH_SHORT).show();
//addPolygon(poligonos);
}
public PolygonOptions addPolygon(ArrayList<Poligonoo> arg) {
PolygonOptions polygonOptions;
for (int i = 0; i <= arg.size(); i++) {
Poligonoo a = arg.get(i);
polygonOptions = new PolygonOptions();
// polygonOptions.addAll(a.getPoo().getPoints()).strokeColor(Color.RED).strokeWidth(2);
polygonOptions.fillColor(Color.parseColor("#51000000"));
return polygonOptions;
}
return null;
}
public void Guardarpol(String nombre) {
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference("Poligono");
Poligonoo poloo;
// for (int i = 0; i < val.size(); i++) {
poloo = new Poligonoo((ArrayList) polygon.getPoints());
Toast.makeText(this, "" + polygon.getPoints(), Toast.LENGTH_SHORT).show();
mDatabase.child(nombre).setValue(poloo).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "se guardo el poligono", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), task.getException().getMessage(), Toast.LENGTH_LONG).show();
}
}
});
//}
}
public void Draw_Map() {
rectOptions = new PolygonOptions();
rectOptions.addAll(val);
rectOptions.strokeColor(Color.BLACK);
rectOptions.strokeWidth(7);
rectOptions.fillColor(0x8000FFFF);
polygon = mMap.addPolygon(rectOptions);
}
public boolean checkLocationPermission() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)) {
new AlertDialog.Builder(this)
.setTitle("Titulo")
.setMessage("Botón")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ActivityCompat.requestPermissions(Root_Map.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION);
}
})
.create()
.show();
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION);
}
return false;
} else {
return true;
}
}
public boolean con() {
return s;
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_LOCATION: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 400, 1, (LocationListener) this);
}
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
}
}
}
entre Desarrolladores
Recibe ayuda de expertos
Registrate y pregunta
Es gratis y fácil
Recibe respuestas
Respuestas, votos y comentarios
Vota y selecciona respuestas
Recibe puntos, vota y da la solución
Pregunta
necesito guardar poligonos en firebase y depues tomar esos poligonos y mostrarlos en maps desde android studio
- preguntó
- Móvil
- 10233 Vistas
- 0 Respuestas
- abierta
0 Respuestas
Por favor, accede o regístrate para responder a esta pregunta.
En el blog
-
- 407088
- 1
- Jul 5, 2015
Sin Respuesta
-
- 155
- 0
- Mar 19
-
- 75
- 1
- Feb 26
-
- 188
- 0
- Ene 30
-
- 1006
- 0
- Nov 7, 2023
-
- 288
- 0
- Sep 19, 2023
-
- 301
- 0
- Ago 21, 2023
-
- 381
- 0
- May 14, 2023
-
- 350
- 0
- Abr 21, 2023
- ver todas
Preguntas relacionadas
- necesito dibujar varios poligonos y guardarlos en firebase, despues cargar esos poligos en el mapa
- Info de firebase en un list view
- Avisar a un usuario cuando esta a cierta distancia de un marcador en Google Maps
- Recuperar datos para realizar validaciones con firebase
- Login no funciona usando Firebase y Flutter
Actividad Reciente
Santiago2610 comentó Mar 23
Acualizar ChoiceField en djangoSantiago2610 preguntó Mar 19
Acualizar ChoiceField en djangogonzalss preguntó Feb 26
Script /boot/ scrapingParkJo preguntó Ene 30
No me deja instalar Oracleelporfirio respondió Ene 10
Actualizar la imagen con los datos devuelto en un …ovedg preguntó Dic 31, 2023
Actualizar la imagen con los datos devuelto en un …Ehdez preguntó Nov 7, 2023
Necesito en wordpress un pluging que me calcule la…pedrourday preguntó Sep 19, 2023
Alternativas a ThreeJS y BabylonJS?pedrourday preguntó Ago 21, 2023
¿Que tecnologias y lenguajes me recomiendan?Fabio respondió Jul 11, 2023
plugin de efecto circular 3d en imagenes
Ultimas Preguntas
Preguntas relacionadas
- necesito dibujar varios poligonos y guardarlos en firebase, despues cargar esos poligos en el mapa
- Info de firebase en un list view
- Avisar a un usuario cuando esta a cierta distancia de un marcador en Google Maps
- Recuperar datos para realizar validaciones con firebase
- Login no funciona usando Firebase y Flutter
Usuarios Top
- Leonardo-Tadei
- 227320 Puntos
- Peter
- 150460 Puntos
- white
- 75880 Puntos
- carlossevi
- 63580 Puntos
- magarzon
- 30650 Puntos
- pregunton
- 20400 Puntos
Todos los Usuarios Usuarios Nuevos
...