0

My Basic UI

I have a very basic UI where i want the user to able to save the latitude and longitute of the location they want to set a geofence to. What I'm wondering is how do i get both latitude and longitude and convert it into latlng and then pass the value into my map activity into an array list.Any help would be greatly Appreciated.

ApprovedAreas = new ArrayList<>();

    ApprovedAreas.add(new LatLng(37.4205940 ,-122.044 ));
    ApprovedAreas.add(new LatLng(37.459979 ,-122.138770 ));
    ApprovedAreas.add(new LatLng(37.4475940 ,-122.9044 ));




 
  • if you want to pass data between activities you should use `Bundle` check this : https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application – Farid Aug 08 '20 at 13:53

1 Answers1

0

In this activity

    ArrayList<LatLng> areas  =  new ArrayList<LatLng>();
    savezone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    areas.add(new LatLng(Double.parseDouble(latitude.getText().toString()),Double.parseDouble(longitude.getText().toString()));
                }
            }); 


gotomap.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  Intent i = new Intent(currentactivity.this, mapactivity.class);
                 i.putParcelableArrayListExtra("areas", areas);
startActivity(intent);
                }
            }); 
    

In mapactivity

ArrayList<LatLng> areas  =  getIntent().getExtras().getParcelableArrayList("areas");  
aryanknp
  • 1,135
  • 2
  • 8
  • 21
  • hi thanks for answering however on the line (new LatLng(latitude.getText().toString(),longitude.getText().toString()); i had an error it said Latlong (double , double) in latlng cannot be applied to (java,langstring,javalangstring) – VenusianAura Aug 08 '20 at 14:58
  • use Double.parseDouble to convert string to double – aryanknp Aug 08 '20 at 15:01
  • how do i do that, so sorry i'm still learning android thanks for the help btw – VenusianAura Aug 08 '20 at 15:18