Skip to content
Snippets Groups Projects
Commit 546e0bfe authored by Ignacio Hernández de la Fuente's avatar Ignacio Hernández de la Fuente
Browse files

stuff

parent 770e5afb
Branches map
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ android {
dependencies {
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
......
......@@ -16,6 +16,7 @@ import com.google.android.gms.maps.model.MarkerOptions
import com.example.googlemapsapp.databinding.ActivityMapsBinding
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.material.floatingactionbutton.FloatingActionButton
class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
......@@ -26,6 +27,10 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
private val permissionCode =101
private lateinit var fab: FloatingActionButton
private var isFabClicked = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -34,10 +39,21 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
fusedLocationProviderClient= LocationServices.getFusedLocationProviderClient(this)
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
fab = findViewById(R.id.fab)
fab.setOnClickListener {
isFabClicked = true
Toast.makeText(applicationContext, "Haz clic en el mapa para colocar un marcador", Toast.LENGTH_LONG).show()
}
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
}
getCurrentLocationUser()
private fun placeMarker(latLng: LatLng) {
// Coloca un marcador en la ubicación proporcionada
mMap.addMarker(MarkerOptions().position(latLng).title("Marcador Personalizado"))
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f))
}
private fun getCurrentLocationUser(){
......@@ -58,9 +74,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
Toast.makeText(applicationContext, currentLocation.latitude.toString()+""+currentLocation.longitude.toString(),
Toast.LENGTH_LONG).show()
val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
placeMarker(LatLng(currentLocation.latitude, currentLocation.longitude))
}
}
}
......@@ -81,11 +95,17 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
}
override fun onMapReady(googleMap: GoogleMap) {
val latLng =LatLng(currentLocation.latitude, currentLocation.longitude)
val markerOptions =MarkerOptions().position(latLng).title("Current Location")
googleMap?.animateCamera(CameraUpdateFactory.newLatLng(latLng))
googleMap?.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 7f))
googleMap?.addMarker(markerOptions)
// El mapa está listo para ser utilizado
mMap = googleMap
// Configura el listener de largo clic en el mapa
mMap.setOnMapLongClickListener { latLng ->
if (isFabClicked) {
// Se llama cuando el usuario realiza un largo clic en el mapa después de presionar el botón flotante
placeMarker(latLng)
}
isFabClicked = false
}
getCurrentLocationUser()
}
}
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<!-- Add your vector drawable content here -->
</vector>
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
\ No newline at end of file
tools:context=".MapsActivity">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/fab"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_dialog_info"
android:contentDescription="@string/fab_description" />
</RelativeLayout>
<resources>
<string name="app_name">GoogleMapsApp</string>
<string name="title_activity_maps">MapsActivity</string>
<string name="fab_description">Descripción del botón flotante</string>
</resources>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment