Click-through button for location? [closed]

1

How to configure a button so that when clicked open the maps and send the user to an address?

    
asked by anonymous 07.06.2017 / 18:10

2 answers

1

Try this:

private void abrirRota(){

    /**
     * Nossa intenção será um google.navigation
     * Temos os seguintes parametros:
     * q= [Destino, endereço ou Latitude e longitude]; OBRIGATÓRIO!
     * mode= [define o método de transporte] {d= condução, w = caminhada, b = bicicleta}; OPCIONAL
     * avoid=[define os recursos que a rota deve tentar evitar] {t = pedágios, h = estradas, f=  balsas} OPCIONAL
     */

    final String url = String.format(Locale.getDefault(),  "google.navigation:q=Heitor+Stockler+de+França,+470+-+Centro+Cívico,+Curitiba+-+PR");
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
}
    
07.06.2017 / 21:06
3

First, create map activity, here's a Example .

Next, create a method to open the activity and associates with the onClick of the button, something like

public void getLocalizacao(View view) {
    Intent i = new Intent(getApplication(), Mapa.class);
    startActivity(i);
}

Returning to map activity, you can set the location:

public void onMapReady(GoogleMap googleMap) {
    LatLng congresso = new LatLng(-15.7997586, -47.8647535);

And to be nice, add an animation where you set the location

CameraPosition cameraPosition = new CameraPosition.Builder() .target(congresso) .zoom(16).bearing(0) .build(); mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    
07.06.2017 / 20:22