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 8085039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:59:15+00:00 2026-06-05T17:59:15+00:00

I am trying to display latitude and longitude values in a TextView , but

  • 0

I am trying to display latitude and longitude values in a TextView, but while running the project the values are not displayed. Can anyone help me?,Thank you in advance. My code is below:
GeocodingActivity.class

public class GeocodingActivity extends Activity {
LocationManager locman;
Criteria cri;
LocationProvider locpro;
AlertDialog.Builder builder;
Handler handler;
TextView t1;
LocationListener loclis;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    t1=(TextView)findViewById(R.id.textView1);
    locman=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
       handler=new Handler(){
        public void handle(Message msg){
                  switch(msg.what){
        case 1: 
            t1.setText((String)msg.obj);
            break;
        }

        }
loclis=new LocationListener(){

        @Override
        public void onLocationChanged(Location location) {
            // TODO Auto-generated method stub
Message.obtain(handler, 1,   arg0.getLatitude()+","+arg0.getLongitude()).sendToTarget();

}
@Override
public void onProviderDisabled(String provider) {
}

@Override
public void onProviderEnabled(String provider) {
    }
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
     }
    };


}

}
  • 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-06-05T17:59:16+00:00Added an answer on June 5, 2026 at 5:59 pm
    Message.obtain(handler,0,location.getLatitude()+","+location.getLongitude()).sendToTarget();
    

    So you must realize that both methods getLongitude and getLatitude returns Double. And you need String.
    So you need to convert them to String with method String.valueOf()

    Message.obtain(handler, 0, String.valueOf(location.getLatitude()) + "," + String.valueOf(location.getLongitude())).sendToTarget();
    

    Then, Message.obj returns Object so for getting String from there you should cast it to String so t1.setText((String) msg.obj);

    Now, it should works.


    EDIT:

    Second approach

    @Override
    public void onLocationChanged(Location location) {
       Bundle bundle = new Bundle();
       String data = String.valueOf(location.getLatitude()) + "," + String.valueOf(location.getLongitude());
       bundle.putString("updateGpsData", data);
       yourMessage.setData(bundle);
       yourMessage.obtain(handler, 0).sendToTarget();
    

    }

    Then your handle method can looks like this

    public void handle(Message msg){
       t1.setText(msg.getData().getString("updateGpsData"));
    }
    

    So you can create Bundle and your updated data just add to Bundle and then with setData() you set data for your Message and in handle method you call getData().getString() for retrieve your update GPS data.

    Don’t forget that Bundle works on pair key + value so you set data to your Bundle with specific key so for get data you have to use same key (“updateGpsData”).

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

Sidebar

Related Questions

I'm trying to display the latitude and longitude values of an address which the
I'm trying to display both the longitude and latitude in seperate textviews after the
Im trying to display hyperlinks (formated as hyperlink) in a listview row but not
I am trying to use a longitude/latitude converter to display the OSGR value. This
Can anyone help solve this problem, no matter what i try i cannot display
i am trying to convert a city's longitude/latitude position to Cartesian so i can
I'm trying display error messages on a form but only one is displayed (the
Im trying to display some files in a web page so the user can
I am trying to display all possible values for a sub-property. Below I am
I am trying to get the current longitude and latitude right before the table

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.