I have tried work on this for whole day but could find a solution. I am working on a test google map app to learn java. From this activity when button is clicked, it takes user to another activity and I need some values to be passed to next activity. I am able to retrieve Start Address as well as destination address in next activity but not the distance.
implements GeoTask.Geo {
private TextView mFromAddress;
private TextView mToAddress;
String str_from,str_to;
int dist;
public void onClickBtn(View v){
str_from = mFromAddress.getText().toString();
str_to = mToAddress.getText().toString();
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=" + str_from + "&destinations=" + str_to + "&mode=driving&language=en-US&avoid=tolls&key=API-Key";
new GeoTask(MapsActivity.this).execute(url);
getResults();
}
// This is called from external class GeoTask.Java
public void setDouble(String result) {
String res[]=result.split(",");
Double min = Double.parseDouble(res[0])/60;
dist = Integer.parseInt(res[1])/1000;
}
public void getResults(){
Intent intent = new Intent(this, ResultsActivity.class);
String fromCity = str_from;
String toCity = str_to;
int kmDistance = dist;
intent.putExtra("from",fromCity);
intent.putExtra("to",toCity);
intent.putExtra("distance",kmDistance);
startActivity(intent);
}
}
I am retrieving these details by
Intent intent = getIntent();
String fromCity = intent.getStringExtra("from");
String toCity = intent.getStringExtra("to");
int kmDistance = intent.getIntExtra("distance", 0);