Mapas
Creación de una App de Mapas usando el API de Google Maps
Cómo comenzar a utilizar Google Maps Platform
Consola de Google Cloud Platform
Get started
Modificar fichero res/values/google_maps_api.xml (poner API Key)
<resources> <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIza . . .</string> </resources>
Manifiesto
<!-- The API key for Google Maps-based APIs is defined as a string resource. (See the file "res/values/google_maps_api.xml"). Note that the API key is linked to the encryption key used to sign the APK. You need a different API key for each encryption key, including the release key that is used to sign the APK for publishing. You can define the keys for the debug and release targets in src/debug/ and src/release/. --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" />
MapsActivity.kt
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle 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 internal class MapsActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mMap: GoogleMap override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_maps) // Obtain the SupportMapFragment and get notified when the map is ready to be used. val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this) } /** * 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 fun onMapReady(googleMap: GoogleMap) { mMap = googleMap // Add a marker in Sydney and move the camera val sydney = LatLng(-34.0, 151.0) mMap.addMarker(MarkerOptions() .position(sydney) .title("Marker in Sydney")) mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)) } }
Mostrar Málaga:
val malaga = LatLng(36.719, -4.453)
Android Samples
Google Maps Android API Demos
Tutorials
(añadir al fichero local.properties la línea MAPS_API_KEY=myAPIKey)
Polylines and Polygons to Represent Routes and Areas
Select Current Place and Show Details on a Map
Repositorio en GitHub de los tutoriales
Código de los tutoriales: maps_tutorials_java
Ejemplo: Controlar mapa
Ejemplo: Eventos sobre el mapa
Codelab: Add a map to your Android app (Kotlin)
Más información:
Deja una respuesta
Lo siento, debes estar conectado para publicar un comentario.