1

Hi guys I wanna launch navigation in a point with google maps with my map but I don't know how to keep my position that is set as "start position". My app have in the main activity the map, and in another activity the button that launch navigation but as I've said, I can't keep "my position". How can I do? Below my call to google maps from the activity without the maps.

    directionButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Marker marker = null;
            BuildInfoMatrix latlong = new BuildInfoMatrix();
            MainActivity main = new MainActivity();
            latlong.Fill_Matrix();
            // **************************************************
            /* Richiamare google maps per la navigazione */
            /*********************************************/
            String destLat = latlong.getLatitude(nomeditta).replaceAll(",", ".");//ritorna lat.replaceAll(",", ".");
            String destLng = latlong.getLongitude(nomeditta).replaceAll(",", ".");

            String uri = String.format("geo:%s,%s?q=%s,%s", marker.getPosition().latitude,marker.getPosition().longitude,destLat,destLng);
            Intent prova = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            startActivity(prova);
            /*********************************************/

        }
    });
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Pierpaolo Ercoli
  • 1,028
  • 2
  • 11
  • 32

1 Answers1

0

I solved with this:

GPSTracker tracker = new GPSTracker(getApplicationContext());
double latitude = tracker.getlatitude();
double longitude = tracker.getlongitude();

This is all my code:

    directionButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Marker marker = null;

            GPSTracker tracker = new GPSTracker(getApplicationContext());


            BuildInfoMatrix latlong = new BuildInfoMatrix();
            MainActivity main = new MainActivity();
            latlong.Fill_Matrix();
            // **************************************************
            /* Richiamare google maps per la navigazione */
            /*********************************************/
            String destLat = latlong.getLatitude(nomeditta).replaceAll(",", ".");//ritorna lat.replaceAll(",", ".");
            String destLng = latlong.getLongitude(nomeditta).replaceAll(",", ".");

            String uri = String.format("geo:%s,%s?q=%s,%s", tracker.latitude, tracker.longitude,destLat,destLng);
            Intent prova = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            startActivity(prova);
            /*********************************************/

        }
    });
Pierpaolo Ercoli
  • 1,028
  • 2
  • 11
  • 32