2013-04-21 8 views
6

पर लैट्लिंग उदाहरण कैसे भेजें I मुझे 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);  
    } 
} 
} 

यह मेरा मार्ग वर्ग है। मुझे समस्या नहीं पता। यहां मेरी मदद करो। ऐसा लगता है कि बंडल ठीक है लेकिन इसे प्राप्त करते समय एक त्रुटि हुई है। अब

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

अपने इरादे के लिए देते:

उत्तर

18

एक बंडल से जुड़ी LatLng वस्तु को putParcelable विधि का उपयोग

i.putExtra("bundle", args); 

अपने नए गतिविधि में इसे पाने के लिए:

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

'सेशन 'और' toPosition' 'int' नहीं हैं .... वे' LatLng' हैं। – Doomsknight

+0

धन्यवाद! संपादन में फिक्स्ड। – wangyif2

+0

विधि getArguments() प्रकार –

संबंधित मुद्दे