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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:16:05+00:00 2026-05-28T00:16:05+00:00

Im new to android and i am trying to make a program that outputs

  • 0

Im new to android and i am trying to make a program that outputs the longitude and latitude integers to the screen inside text fields.

Ive have two edit text fields:

<EditText
        android:id="@+id/longitudeField"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <EditText 
        android:id="@+id/latitudeField"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text"/>

I know have a java file that runs a class called EmergencyLocation.
In this file i set the longitude and latitude and try to output these to the screen via the edit text fields but every time i do this nothing comes up.

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Context;
import android.location.LocationManager;
import android.location.Criteria;

        public class EmergencyLocation extends Activity implements LocationListener 
        {
            private TextView latitudeField;
            private TextView longitudeField;
            private LocationManager locationManager;
            private String provider;

            @Override
            public void onCreate(Bundle savedInstanceState)
            {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                latitudeField = (TextView) findViewById(R.id.latitudeField);
                //logitudeField = (TextView) findViewById(R.id.????);

                locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

                Criteria criteria = new Criteria();
                provider = locationManager.getBestProvider(criteria, false);
                locationManager.requestLocationUpdates(provider, 0, 0, this);
                Location location = locationManager.getLastKnownLocation(provider);
                onLocationChanged(location);
            }

            @Override
            public void onDestroy()
            {
                super.onDestroy();
                locationManager.removeUpdates(this);
            }

            @Override
            public void onLocationChanged(Location location) 
            {
                if(location != null)
                {
                    System.out.println("Provider " + provider + " has been selected.");
                    int lat = (int) (location.getLatitude());
                    //int lng = (int) (location.getLongitude());
                    latitudeField.setText(String.valueOf(lat));
                    //longitudeField.setText(String.valueOf(lng));
                }
                else
                {
                    latitudeField.setText(String.valueOf("Provider not avaliable"));
                    //the same with long stuff
                }
            }
            @Override
            public void onProviderDisabled(String provider) {
                // TODO Auto-generated method stub

            }
            @Override
            public void onProviderEnabled(String provider) {
                // TODO Auto-generated method stub

            }
            @Override
            public void onStatusChanged(String provider, int status,
                    Bundle extras) {
                // TODO Auto-generated method stub

            } 
        }

as i said before im new to android and i think it is something very simple im missing.

thanks in advance

  • 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-28T00:16:05+00:00Added an answer on May 28, 2026 at 12:16 am

    I’ve tested your app. It is working and location is updating. May be you forget to specify LOCATION-permisions in AndroidManifest.xml?

    Also, here:

    provider = locationManager.getBestProvider(criteria, false);
    

    provider may be null. In this case you will receive an exception while trying to do

    locationManager.requestLocationUpdates(provider, 0, 0, this);
    

    So, you should check provider for “null” before calling requestLocationUpdates().

    Also, is there any problem with longitude?

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

Sidebar

Related Questions

I'm new to android and I'm trying to make a simple android program that
I'm new to android development and I'm trying to make an android app that
Hi I'm new to Android Programming and I'm trying to make a simple program
I'm trying to make test-program that opens a website by pushing a button. I
hey, im new to android development and trying to make my first application. What
I'm new in android and i'm trying to make an android app to display
I'm new at android developing. I'm trying to make a simple drumset app, when
im fairly new to android development, but i'm having some trouble trying to make
I am trying to make an app that opens android market page of selected
I am new in Android. I am trying to make an RPC to fetch

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.