0

I am looking advice on options i have to save data from markers and searches from placepicker on google maps.

Ive looked into shared preferences and tried the code out but not working.

I need to take address data from a place picker search and save it so that a history activity can generate a list.

is there any option that place picker saves searches?

im using android studio

This is an example of my place picker

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


            LatLng placeLatLng = place.getLatLng(); // gett lat lng from place
            double placeLat = placeLatLng.latitude;
            double placeLong = placeLatLng.longitude;
            final CharSequence name = place.getName();
            final CharSequence address = place.getAddress();
            Marker destination = mMap.addMarker(new MarkerOptions().position(new LatLng(placeLat, placeLong)).title("This is your destination"));

            LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            //Current Location
            Criteria criteria = new Criteria();
            String provider = locationManager.getBestProvider(criteria, true);
            Location myLocation = locationManager.getLastKnownLocation(provider);

            //Current Location LatLong
            final double currentLat = myLocation.getLatitude();
            final double currentLng = myLocation.getLongitude();


            List<CharSequence> listItems = new ArrayList<>();


            //Directions From Current Location To Destination
            final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?" + "saddr=" + currentLat + "," + currentLng + "&daddr=" + placeLat + "," + placeLong));
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            listItems.add(name);
            listItems.add(address);
            startActivity(intent);
}
    }
    public void saveInfo(View v){
        SharedPreferences sharedPreferences = getSharedPreferences("Place Deatils", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
    }

1 Answers1

0

get location address using Geocoder and store the information in SharedPreferences

   Geocoder geocoder;
            List<Address> addresses;
            geocoder = new Geocoder(this, Locale.getDefault());

            try {
                addresses = geocoder.getFromLocation(latt,lang, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
                String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
                String area = addresses.get(0).getSubLocality();
                String dist= addresses.get(0).getSubAdminArea();
                String city = addresses.get(0).getLocality();             
                mapMarker.setTitle(area+","+dist+","+city);
            } catch (IOException e) {
                e.printStackTrace();
            }

check this SharedPreferences

Community
  • 1
  • 1
Rgv
  • 504
  • 5
  • 23