How to open, via intent, the Google Maps app in certain Latitude / Longitude?

1

Using this rule, I can view the information in the database. I'm trying to put a button to get the latitude and longitude of the database so when you click it open google maps.

public class UsuarioAdapter extends ArrayAdapter<Usuario> {
    private Context context;
    private ArrayList<Usuario> lista;

    public UsuarioAdapter(Context context, ArrayList<Usuario> lista){
        super(context,0,lista);
        this.context = context;
        this.lista = lista;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Usuario itemPosicao = this.lista.get(position);

        convertView = LayoutInflater.from(this.context).inflate(R.layout.item_lista,null);
        final View layout = convertView;

        TextView textViewNome = (TextView) convertView.findViewById(R.id.textViewNome);
        textViewNome.setText(itemPosicao.getNome());

        TextView textViewCrm = (TextView) convertView.findViewById(R.id.textViewCrm);
        textViewCrm.setText(itemPosicao.getCrm());

        TextView textViewTelefone = (TextView) convertView.findViewById(R.id.textViewTelefone);
        textViewTelefone.setText(itemPosicao.getTelefone());

        TextView textViewConvenios = (TextView) convertView.findViewById(R.id.textViewConvenios);
        textViewConvenios.setText(itemPosicao.getConvenios());


    TextView textViewLatitude = (TextView) convertView.findViewById(R.id.textViewLatitude);
    textViewLatitude.setText(itemPosicao.getLatitude());

    TextView textViewLongitude = (TextView) convertView.findViewById(R.id.textViewLongitude);
    textViewLongitude.setText(itemPosicao.getLongitude());

        Button button = (Button)convertView.findViewById(R.id.buttonComoChegar);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


            }
        });
        return convertView;
    }
}

How can I do this?

    
asked by anonymous 24.10.2015 / 00:31

1 answer

2

Having the latitude and longitude available in the User class this data can be obtained in the same way as "Name", "Crm", "Phone", etc.
Then just create Intent to launch Google maps .

    .......
    .......
    double final latitude = itemPosicao.getLatitude();
    double final longitude = itemPosicao.getLongitude();

    Button button = (Button)convertView.findViewById(R.id.buttonComoChegar);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String strUri = "http://maps.google.com/maps?q=loc:" + 
                             latitude + "," + longitude;
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                                       Uri.parse(strUri));

            intent.setClassName("com.google.android.apps.maps",
                                "com.google.android.maps.MapsActivity");

            context.startActivity(intent);

        }
    });

You can also use a temp built like this:

Uri mapAppUri = Uri.parse("geo:" + latitude + ","
        + longitude + "?q="
        + latitude + ","
        + longitude
        + "(" + Uri.encode("nome do local") + ")");
Intent intent = new Intent(Intent.ACTION_VIEW, mapAppUri);

The advantage is that if there are other applications installed that can handle locations they will be presented to the user to choose one.

    
24.10.2015 / 16:10