Giter Club home page Giter Club logo

course-android-location-services-planear-dia's Introduction

Planear Día

Aplicación de ejemplo de uso de Google Places y Google Maps.

Este proyecto es parte del Curso de servicios de localización en Android

Place Picker esta deprecado, se necesita actualizar este proyecto a 'com.google.android.libraries.places:places:2.2.0' para que funcione correctamente.

Paso 1

Abrir la pantalla de selección de lugares de Google Places.

PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
    startActivityForResult(builder.build(this), 888);
} catch (Exception e) {

}

Paso 2

Obtener la respuesta luego de la selección.

Place place = PlacePicker.getPlace(this, data);

String nombre = place.getName().toString();
String direccion = place.getAddress().toString();
double latitud = place.getLatLng().latitude;
double longitud = place.getLatLng().longitude;
String telefono = place.getPhoneNumber() != null ? place.getPhoneNumber().toString() : "No tiene teléfono";
String website = place.getWebsiteUri() != null ? place.getWebsiteUri().getAuthority() : "No tiene website";

Database.guardarUbicacion(this, nombre, direccion, latitud, longitud, telefono, website);

Paso 3

Mostrar los lugares en forma de marcador con una línea entre ellos.

PolylineOptions polylineOptions = new PolylineOptions()
                .color(ContextCompat.getColor(this, R.color.colorPrimary))
                .width(8);

for (int i = 0; i < lugares.size(); i++) {
    Lugar l = lugares.get(i);

    LatLng punto = new LatLng(l.getLatitud(), l.getLongitud());

    MarkerOptions markerOptions = new MarkerOptions()
        .position(punto)
        .title(l.getNombre())
        .snippet(l.getDireccion());

    mMap.addMarker(markerOptions);

    polylineOptions.add(punto);
}
mMap.addPolyline(polylineOptions);

Paso 4

Hacer que la cámara centree los todos puntos en la pantalla.

Antes del for

LatLngBounds.Builder builder = new LatLngBounds.Builder();

Dentro del for

builder.include(punto);

Al final y afuera del for

LatLngBounds bounds = builder.build();
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10));

course-android-location-services-planear-dia's People

Contributors

alvareztech avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

course-android-location-services-planear-dia's Issues

PlacePicker is deprecated

Place Picker esta deprecado, se necesita actualizar este proyecto a 'com.google.android.libraries.places:places:2.2.0' para que funcione correctamente.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.