0

How do I put the latitude and longitude from SQLite database to daddr= on this intent:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                  Uri.parse("http://maps.google.com/maps?f=d&saddr=&daddr=));

I have a table that contains these fields:

  • _id for id
  • name for hotel name
  • lat for latitude
  • long for longitude

Here is my code:

public class HotelList extends Activity{
hotelHelper dbHotelHelper;
protected Cursor cursor;
protected ListAdapter adapter;
ListView numberList;    

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hotellist);

    numberList = (ListView)findViewById(R.id.hotelListView);
    numberList.setOnItemClickListener(new OnItemClickListener() {           
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&saddr=&daddr="));
            startActivity(intent);              
        }
    });

    dbHotelHelper = new hotelHelper(this);
    try{
        dbHotelHelper.createDataBase();         
    }
    catch (Exception ioe){
        Log.e("err","Unable to create database");
    }

    view();   

    }

private void view() {
    // TODO Auto-generated method stub
    SQLiteDatabase db = dbHotelHelper.getReadableDatabase();
    try{
        cursor = db.rawQuery("SELECT * FROM hoteltbl", null);
        adapter = new SimpleCursorAdapter(
                this, 
                R.layout.hotelview, 
                cursor, 
                new String[]{"name"}, 
                new int[] {R.id.hotelname}
                );
        numberList.setAdapter(adapter);     
    }
    catch (Exception e){
        Log.e("error",e.toString());
    }       
}   
}
makes
  • 6,438
  • 3
  • 40
  • 58
forgiven24
  • 49
  • 2
  • 10

1 Answers1

1

Take a look at : http://www.askdavetaylor.com/how_to_add_google_maps_directions_tool_search_web_site.html

Then, you can use String.format() function to fill your URL :

String intentUrl = String.format("http://maps.google.com/maps?f=d&saddr=%s&daddr=%s&...",...);

Hope it helps.

Camille R
  • 1,433
  • 2
  • 17
  • 29
  • 1
    Thanks for the answer, but can you give me the instant code to use it on my code... such as query to put the lat and long on daddr=. – forgiven24 Nov 16 '11 at 16:12
  • This is exactly what you need i think : http://stackoverflow.com/questions/2662531/launching-google-maps-directions-via-an-intent-on-android – Camille R Nov 16 '11 at 16:24