Pass Latitude/longitude via intent

非 Y 不嫁゛ 提交于 2019-12-08 05:50:42

问题


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!



来源:https://stackoverflow.com/questions/28572267/pass-latitude-longitude-via-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!