Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:17:02+00:00 2026-05-27T02:17:02+00:00

I really need your help. I have a database with latitude and longitude data,

  • 0

I really need your help.

I have a database with latitude and longitude data, here the example:

id_____name_____lat_________long

1_____hotel one___6.1234______-106.12345

2____hotel two____6.54321_____-107.23456

3___hotel three___7.12345_____-106.98765

The data display in ListView on Android. And i use onItemClick, so if i click one of the item in ListView it will go to

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

But the problem is if i click one of the item in ListView the data in lat_var and long_var on intent above won’t give me the lat and long data from my database…

Here my code, can you edit it, so if i click one of the item in ListView it will give me the lat and long data from my database. For example if i click hotel two the lat_var will change to 6.54321 and the long_var will change to -107.23456 on that intent.

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            SQLiteDatabase dbs = dbHotelHelper.getReadableDatabase();

            String get_lat = "SELECT lat FROM hoteltbl";
            Cursor result_lat = dbs.rawQuery(get_lat, null);
            double lat_var = result_lat.getColumnIndex("lat");
            String get_long = "SELECT lat FROM hoteltbl";
            Cursor result_long = dbs.rawQuery(get_long, null);
            double long_var = result_long.getColumnIndex("long");

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

        }

I don’t know if the problem is my syntax or what. Please fix my code. I really thanks for anyone who answer this…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:17:03+00:00Added an answer on May 27, 2026 at 2:17 am

    First, only one query is necessary. No need to query your table twice.
    Second, you need to adapt your query with parameters from your selection:

    @Override
    protected void onListItemClick(ListView listView, View view, int position, long id) {id) {    
        String selectedItem = (String) getListAdapter().getItem(position);
        String query = "SELECT lat, long FROM hoteltbl WHERE name = '" + selectedItem + "'";
        SQLiteDatabase dbs = dbHotelHelper.getReadableDatabase();
        Cursor result = dbs.rawQuery(query, null);
        result.moveToFirst();
    
        double lat = result.getDouble(result.getColumnIndex("lat"));
        double long = result.getDouble(result.getColumnIndex("long"));
    
        ....
    

    This code was written in the StackOverflow editor, it might not work as such, but will give you an idea.

    (Also, don’t add suffixes “_var”, or “_long” to your variables, it’s not necessary in a strongly-typed language like Java)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a security problem here and we really need your help and inputs.
I've some questions .. and I really need your help. I have an application.
I really need your help: I have installed easphp on my laptop (apache, php,
I'm a beginner and I really need your help! I have an XML file
I have a scenario and I really need your help. I have a Silverlight
i am new to iOS programming. i really need your help. i have a
I really need your help in my issue very quickly and it's too close
I really need your help for this. I am relatively new to programming and
i really need your help with a CSS-Layout. I tried a few time, however
Afternoon all, I really need your help as this is a Nightmare! I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.