0% found this document useful (0 votes)
53 views16 pages

Clase 11 Android

The document shows code for adding markers and images to markers on a Google Map. It includes code for setting marker positions, adding draggable markers, and adding custom images to markers. The code demonstrates basic Google Maps functionality in Android.

Uploaded by

Josias Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views16 pages

Clase 11 Android

The document shows code for adding markers and images to markers on a Google Map. It includes code for setting marker positions, adding draggable markers, and adding custom images to markers. The code demonstrates basic Google Maps functionality in Android.

Uploaded by

Josias Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

console.developers.google.

com
Habilitar
Crear proyecto

AIzaSyBTyg7av-dxya4deKX3OeVNBGQ2okQD9q8AIzaSyBTyg7av-
dxya4deKX3OeVNBGQ2okQD9q8package com.holamundo.diseno50.miprimermapa;

import android.support.v4.app.FragmentActivity;
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;
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback {

private GoogleMap mMap;

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

/**
* 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
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Add a marker in Sydney and move the camera


LatLng sydney = new LatLng(14.8440059,-91.5232732);
LatLng sunday= new LatLng(14.8440059,-96.5232730);

mMap.addMarker(new MarkerOptions().position(sydney).title("Api
esta aqui"));
mMap.addMarker(new MarkerOptions().position(sunday).title("no
esta api"));

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(sydney,12.0f));
}
}
package com.holamundo.diseno50.miprimermapa;

import android.support.v4.app.FragmentActivity;
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;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

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

/**
* 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
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Add a marker in Sydney and move the camera


LatLng sydney = new LatLng(14.8440059,-91.5232732);
LatLng sunday= new LatLng(14.8440059,-96.5232730);

mMap.addMarker(new MarkerOptions().position(sydney).title("Api esta aqui"));


mMap.addMarker(new MarkerOptions().position(sunday).title("no esta api"));

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(sydney,12.0f));
}
}
<resources>

<!--

TODO: Before you run your application, you need a Google Maps API key.

To get one, follow this link, follow the directions and press "Create" at the end:

https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyT
ype=CLIENT_SIDE_ANDROID&r=62:E5:DF:17:13:C4:B0:11:EE:7A:57:B8:3B:62:1B:EA:8D:E2:68:A
2%3Bcom.holamundo.diseno50.miprimermapa

You can also add your credentials to an existing key, using this line:

62:E5:DF:17:13:C4:B0:11:EE:7A:57:B8:3B:62:1B:EA:8D:E2:68:A2;com.holamundo.diseno50.mip
rimermapa

Alternatively, follow the directions here:

https://developers.google.com/maps/documentation/android/start#get-key

Once you have your key (it starts with "AIza"), replace the "google_maps_key"

string in this file.


-->

<string name="google_maps_key" templateMergeStrategy="preserve"


translatable="false">AIzaSyBTyg7av-dxya4deKX3OeVNBGQ2okQD9q8</string>

</resources>
//cdigo para mover los iconos

package com.holamundo.diseno50.miprimermapa;

import android.support.v4.app.FragmentActivity;

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;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@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);

/**

* 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

public void onMapReady(GoogleMap googleMap) {

mMap = googleMap;

// Add a marker in Sydney and move the camera

LatLng sydney = new LatLng(14.8440059,-91.5232732);

LatLng mcdonals= new LatLng(14.8440059,-91.5222520);

LatLng estadios= new LatLng(14.8440059,-91.5212710);

LatLng camperitos= new LatLng(14.8440059,-91.5032750);

LatLng templos= new LatLng(14.8440059,-91.40327150);

mMap.addMarker(new MarkerOptions()

.position(sydney)

.title("Api esta aqui")

.draggable(true) //mover iconos o marcadores

);

mMap.addMarker(new MarkerOptions().position(mcdonals)

.title("Mcd esta aqui")

.draggable(true)

);

mMap.addMarker(new MarkerOptions().position(estadios)

.title("estadio esta aqui")

.draggable(true)

);

mMap.addMarker(new MarkerOptions().position(camperitos)

.title("campero esta aqui")

.draggable(true)

);
mMap.addMarker(new MarkerOptions().position(templos)

.title("templo minerva esta aqui")

.draggable(true)

);

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(sydney, 12.0f));

//cdigo para poner imgenes

package com.holamundo.diseno50.miprimermapa;

import android.graphics.Bitmap;

import android.support.v4.app.FragmentActivity;

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.BitmapDescriptor;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;

import com.google.android.gms.maps.model.LatLng;

import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@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);

/**

* 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

public void onMapReady(GoogleMap googleMap) {

mMap = googleMap;

// Add a marker in Sydney and move the camera

LatLng sydney = new LatLng(14.8440059,-91.5232732);

LatLng mcdonals= new LatLng(14.8440059,-91.5222520);

LatLng estadios= new LatLng(14.8440059,-91.5212710);

LatLng camperitos= new LatLng(14.8440059,-91.5032750);

LatLng templos= new LatLng(14.8440059,-91.40327150);

mMap.addMarker(new MarkerOptions()

.position(sydney)

.title("Api esta aqui")

.draggable(true) //mover iconos o marcadores

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
//cambia el color de los iconos o marcadores

.alpha(0.7f)

.snippet("population: 4,137,400")

.icon(BitmapDescriptorFactory.fromResource(R.drawable.camperito)) //pone la
imagen

);

mMap.addMarker(new MarkerOptions()

.position(mcdonals)

.title("Mcd esta aqui")

.draggable(true)

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))

.alpha(0.7f)

.snippet("population: 4,137,400")

.icon(BitmapDescriptorFactory.fromResource(R.drawable.mcdonald)) //pone la
imagen
);

mMap.addMarker(new MarkerOptions().position(estadios)

.title("estadio esta aqui")

.draggable(true)

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))

.alpha(0.7f)

.snippet("population: 4,137,400")

.icon(BitmapDescriptorFactory.fromResource(R.drawable.estadio)) //pone la
imagen

);

mMap.addMarker(new MarkerOptions().position(camperitos)

.title("campero esta aqui")

.draggable(true)

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW))

.alpha(0.7f)

.snippet("population: 4,137,400")

.icon(BitmapDescriptorFactory.fromResource(R.drawable.camperito)) //pone la
imagen

);

mMap.addMarker(new MarkerOptions().position(templos)

.title("templo minerva esta aqui")

.draggable(true)

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN))

.alpha(0.7f)

.snippet("population: 4,137,400")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.templo)) //pone la
imagen

);

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(sydney, 12.0f));

You might also like