【问题标题】:How to put latitude and longitude data from sqlite database to intent?如何将经纬度数据从 sqlite 数据库放入意图?
【发布时间】:2011-11-16 15:55:07
【问题描述】:

我如何将 SQLite 数据库中的纬度和经度放到 daddr= 这个意图上:

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

我有一个包含这些字段的表:

  • _id 为 id
  • name 酒店名称
  • lat 表示纬度
  • long 表示经度

这是我的代码:

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());
    }       
}   
}

【问题讨论】:

    标签: android sqlite google-maps android-intent latitude-longitude


    【解决方案1】:

    看看: http://www.askdavetaylor.com/how_to_add_google_maps_directions_tool_search_web_site.html

    然后,您可以使用 String.format() 函数来填写您的 URL:

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

    希望对你有帮助。

    【讨论】:

    • 感谢您的回答,但您能否给我即时代码以在我的代码中使用它...例如查询将 lat 和 long 放在 daddr= 上。
    • 这正是我认为你需要的:stackoverflow.com/questions/2662531/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    相关资源
    最近更新 更多