-3

I need to navigate via an andress, or to converte my adress into lat&long for use in the uri...

Anyone know how do I do it ?

        @Override
        public void onClick(View v) {
            String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", 231, 321, "Where the party is at");
            Intent MapsIntent= new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(uri));
            MapsIntent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            try
            {
                startActivity(MapsIntent); 
            }
            catch(ActivityNotFoundException ex)
            {
                try
                {
                    Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                    startActivity(unrestrictedIntent);
                }
                catch(ActivityNotFoundException innerEx)
                {
                    Toast.makeText(getApplicationContext(),
                            "Nenhum aplicativo de navegação instalado!", Toast.LENGTH_LONG).show();
                }
            }

        }
    });
  • http://stackoverflow.com/questions/2662531/launching-google-maps-directions-via-an-intent-on-android – Pete Nov 27 '13 at 16:43

1 Answers1

0

to convert address into lat and lng, i use this:

              String addressStr = "your address";
              double latitude,longtitude;
              Geocoder geoCoder = new Geocoder(context);

              try {
                  List<Address> addresses = geoCoder.getFromLocationName(addressStr, 1); 
                  if (addresses.size() >  0) {
                     latitude = addresses.get(0).getLatitude(); 
                     longtitude = addresses.get(0).getLongitude(); 
                  }

              } catch (IOException e) { // TODO Auto-generated catch block
              e.printStackTrace(); }
MikeKeepsOnShine
  • 1,730
  • 4
  • 23
  • 35