Skip to content Skip to sidebar Skip to footer

Passing Gps Coordinates To Activity

I am trying to pass longitude and latitude variables into another activity for the Google maps fragment. So far I have managed to do this Intent i = new Intent(Main.this, Main2.cla

Solution 1:

Give relevant key like

Intent i = newIntent(Main.this, Main2.class);
i.putExtra("longitude", xLocation.getLongitude());
i.putExtra("latitude", xLocation.getLatitude());

and in Main2 Activity

Bundleextras= getIntent().getExtras(); 
if(extras !=null && extras.getDouble("latitude") != null && extras.getDouble("longitude") != null) { 
doublelat= extras.getDouble("latitude");
doublelng= extras.getDouble("longitude");
}

Solution 2:

Try:

Intent i = newIntent(Main.this, Main2.class);
i.putExtra("lon", xLocation.getLongitude());
i.putExtra("lat", xLocation.getLatitude());

Like this:

int lat = getIntent().getExtras().getDouble("lat");
int lon = getIntent().getExtras().getDouble("lon");

Solution 3:

Use getIntent() and getDoubleExtra() in yours second activity. But pass it in different way. First argument in putExtra should be some String but you have to know him, it is needed to use later in second activity. Like:

publicstaticfinalStringFIRST="firstArgument";

i.putExtra(FIRST, xLocation.getLongitude()); 

And in Main2:

double i = getIntent().getDoubleExtra(Main.FIRST, 0);

Post a Comment for "Passing Gps Coordinates To Activity"