Pass Latitude/longitude via intent

2019-06-07 17:52发布

问题:

I have collected different latitude and longitude of locations. I want to know if i can set them as string of array for e.g(String lat = {"9385853.0094", "23123123.234")and then pass them via intent so that i can display the location in google map using lat/long in new activity.

回答1:

For example you have two classes called Maps.java and Routes.java.

Use the following code to pass the LatLng

LatLng fromPosition = new LatLng(9385853.0094, 23123123.234 );
LatLng toPosition = new LatLng(11.145315551, 99.333455333);

Bundle args = new Bundle();
args.putParcelable("from_position", fromPosition);
args.putParcelable("to_position", toPosition);

i.putExtra("bundle", args);

Intent i= new Intent(Maps.this, Routes.class);
        startActivity(i);

And at the receiving end use the following code

Bundle bundle = getIntent().getParcelableExtra("bundle");
LatLng fromPosition = bundle.getParcelable("from_position");
LatLng toPosition = bundle.getParcelable("to_position");

Hope this Helps!