Passing Longitude and Latitude beetween activities

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Passing Longitude and Latitude beetween activities

Postby reza » Fri Jan 28, 2011 9:34 am

I have an activity where user enters an address and click a button.
On the button click, I want to pass the Longitude and Latitude of that address to another activity.
The second activity receives the Longitude and Latitude and displays the map.

The problem is, the second activity is not receiving the Longitude and Latitude.

My first activity:
Code: Select all
Button btnDrive=(Button)findViewById(;
        btnDrive.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
            // TODO Auto-generated method stub
            String txtAddress=address.getText().toString();
                  Dialog locationError=new AlertDialog.Builder(NavigationActivity.this)
                  .setPositiveButton(R.string.hello, null)
                  .setMessage("Sorry,your address does not exist in this world")
                                                       Address x=foundAddresses.get(0);
                                                Intent myIntent=new Intent();
                  Bundle bundle=new Bundle();
                  bundle.putDouble("toLat", srchLat);
                  bundle.putDouble("toLon", srchLon);
               }catch(Exception ex){
                  //error message.

My second activity is:
Code: Select all
public class MapRouteActivity extends MapActivity{
   LinearLayout linearLayout;
    MapView mapView;
    private Road mRoad;
   Bundle bundle=this.getIntent().getExtras();
    public void onCreate(Bundle savedInstanceState) {
            mapView = (MapView) findViewById(;

            new Thread() {
                    public void run() {
                            double fromLat = 55.6873750, fromLon = 12.5039390;
                           //double toLat = 55.7053041;
                            //double toLon = 12.5442230;
                            double toLat=bundle.getDouble("toLat");
                            double toLon=bundle.getDouble("toLon");
                            String url = RoadProvider
                                            .getUrl(fromLat, fromLon, toLat, toLon);
                            InputStream is = getConnection(url);
                            mRoad = RoadProvider.getRoute(is);

Any idea what may the problem be??
[I did not write the full code here rather I wrote the problem area for better understanding.]
Posts: 9
Joined: Sat Jan 22, 2011 12:29 am


Re: Passing Longitude and Latitude beetween activities

Postby JoxTraex » Sat Jan 29, 2011 2:54 am

Instead of using a bundle... (should be the same) put the information into the intent and then fire that intent. Once you are in the second Activity (On create) retrieve that intent:

Bundle b = getIntent().getExtras();

Then using this bundle try retrieve your information from this bundle, it should have your information.

My initial impression is that when the bundle is retrieve its retrieve even BEFORE it goes into the oncreate() which is where it receives the information.

I hope this helps.
Posts: 25
Joined: Wed Jan 26, 2011 12:29 am


Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests