0

How i can pass values from one blank activity to map activity Actually I'm trying to send latitude and longitude values from one activity to maps activity but I'm getting app stopped here is code of location fetch activity.

if(gps.canGetLocation()){
    longitude = gps.getLongitude();
    latitude = gps.getLatitude();
    Toast.makeText(getApplicationContext(), "Longitude:"+Double.toString(longitude)+"\nLatitude:" + Double.toString(latitude), Toast.LENGTH_SHORT).show();
}

and code of maps activity where I want these values are maps activity

LatLng sydney = new LatLng(longi, lati);
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
  • Possible duplicate of [How do I pass data between activities on Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on-android) – Akash Patel Feb 10 '17 at 10:58
  • Could you please show more code? I don't understand if you're stuck on passing data between activities or on using the map class. – michoprogrammer Feb 10 '17 at 11:00

1 Answers1

0

You could use Intent:

first put your Long/Lat values with a String key in the Intent you create to start new Activity:

 long lat = 731414;
 long lng = 134145;
 Intent intent = new Intent(this, MapsActivity.class);
 intent.putExtra("LONGITUDE" , lat);
 intent.putExtra("LATITUDE" , lng);
 startActivity(intent);

In the onCreate of MapsActivity you can getIntent and get the extras with the key you put them in:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    long lat = getIntent().getLongExtra("LONGITUDE", 0);
    long lng = getIntent().getLongExtra("LATITUDE" , 0);
fijili
  • 39
  • 4