6
LatLng 클래스의 인스턴스를 다른 인 텐트로 전달해야합니다. 어떻게해야합니까? 다음은 코드입니다.새로운 의도로 LatLng 인스턴스를 보내는 방법
LatLng fromPosition = new LatLng(23.4555453556, 11.145315551);
LatLng toPosition = new LatLng(12.1115145311, 99.333455333);
Intent i= new Intent(Maps.this, Routes.class);
startActivity(i);
여기에서 도와주세요.
루트 클래스 :
public class Routes extends FragmentActivity {
GoogleMap mMap;
GMapV2Direction md;
private String provider;
double lati;
double longi;
String name;
Location location;
Document doc;
PolylineOptions rectLine;
Bundle bundle = getIntent().getParcelableExtra("bundle");
LatLng fromPosition = bundle.getParcelable("from_position");
LatLng toPosition = bundle.getParcelable("to_position");
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps2);
md = new GMapV2Direction();
mMap = ((SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
LatLng coordinates = fromPosition;
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 16));
mMap.addMarker(new MarkerOptions().position(fromPosition).title("Start"));
mMap.addMarker(new MarkerOptions().position(toPosition).title("End"));
new ParseXML().execute();
}
private class ParseXML extends AsyncTask<Void, Void, Document> {
@Override
protected Document doInBackground(Void... params) {
doc = md.getDocument(fromPosition, toPosition,
GMapV2Direction.MODE_DRIVING);
ArrayList<LatLng> directionPoint = md.getDirection(doc);
rectLine = new PolylineOptions().width(3).color(Color.RED);
for (int i = 0; i < directionPoint.size(); i++) {
rectLine.add(directionPoint.get(i));
}
return null;
}
@Override
protected void onPostExecute(Document result) {
// TODO Auto-generated method stub
mMap.addPolyline(rectLine);
}
}
}
이 내 경로 클래스입니다. 나는 그 문제를 모른다. 도와주세요. 번들을 잘 보낸 것처럼 보이지만 수신하는 동안 오류가 있습니다.
'fromPosition'과'toPosition'은'int'가 아닙니다 .... 그들은'LatLng'입니다. – Doomsknight
감사! 수정시 수정되었습니다. – wangyif2
getArguments() 메서드는 Routes 유형에 대해 정의되지 않았습니다. –