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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:39:02+00:00 2026-06-14T14:39:02+00:00

here’s the thing. i used the same function i did in separated class that

  • 0

here’s the thing. i used the same function i did in separated class that only contain specific for gps just for try out. it works although i must say the coordinate value is incorrect. now i tried to implement the same function in my real project and it is not working. it did detect whether i enable or disable the GPS in my phone but the are no values of coordination appears.

for the code, i made two classes. Froyo2Activity and MyLocationListener. Froyo2Activity is the main activity which only extends Activity and MyLocationListener implements LocationListener. For better view, here’s my code.

public class Froyo2Activity extends Activity{
Spinner priorSpin, genderSpin;
ImageView femaleView, maleView;
Button submit, agePrev, ageNext, bpPrev, bpNext, pPrev, pNext, butLoc;
SeekBar seekAge, seekBP;
EditText ageEdit, bpEdit, pEdit, locEdit, fname, lname; 
TextView tv;

String commandline="", ageString="", bpString="", pString="";
int age = 0, bp = 0, p = 0;
double latitude, longitude, altitude, pitch = 0;    

private static final int REQUEST_CODE = 10;
private LocationManager locationManager;
private String provider;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_froyo2);       

    fname = (EditText) findViewById(R.id.editText1);
    lname = (EditText) findViewById(R.id.editText2);
    ageEdit = (EditText) findViewById(R.id.editText7);
    pEdit = (EditText) findViewById(R.id.editText9);
    locEdit = (EditText) findViewById(R.id.editText3);
    femaleView = (ImageView)findViewById(R.id.femaleView);
    maleView = (ImageView)findViewById(R.id.maleView);
    priorSpin = (Spinner) findViewById(R.id.prior_spin);
    genderSpin = (Spinner)findViewById(R.id.gender_spin);
    tv = (TextView) findViewById(R.id.textView14);


    //---set the GPS---
    //Get the location manager
    LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
      LocationListener mlocListener = new MyLocationListener();
      mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

      if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
          if(MyLocationListener.latitude>0)
          {
              latitude=MyLocationListener.latitude;
              longitude=MyLocationListener.longitude;
              tv.setText("Latitude: "+ Double.toString(latitude) +" Longitude: "+  Double.toString(longitude)+" Altitude:"+  Double.toString(pitch)+"");                        
           }
           else
           {
              tv.setText("Signal Not Available");
            }
        } else {
            tv.setText("GPS is not turned on...");              
       }
    //---end GPS---

this is the code for MyLocationListener

 package com.example.froyo2;

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

public class MyLocationListener implements LocationListener {
public static double latitude;
public static double longitude;
public static double salah=90;



@Override
public void onLocationChanged(Location loc)


   {
//        loc.getLatitude();
//        loc.getLongitude();
        latitude=loc.getLatitude();
        longitude=loc.getLongitude();
        salah=1;
}

@Override
public void onProviderDisabled(String provider)
{
    salah=2;
}

@Override
public void onProviderEnabled(String provider)
{


    salah=3;
    }

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

does anyone knows how to solve this. like i said before, when im doing tryout with the gps function with its own class; meaning without implementing other function or activity and specifically the class tested only for GPS function, it does work – at least pointing out the number of the location. however, when implementing the GPS with other function, it said the Signal Not Available (please refer to the code). It would be helpful if this matter could be solved.

Thanks for advance.
(SaraBrown)

  • 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-14T14:39:03+00:00Added an answer on June 14, 2026 at 2:39 pm

    Use below code:

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                    MINIMUM_TIME_BETWEEN_UPDATES,
                    MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
    

    For locationListener you may use this (Put this inside your Froyo2Activity):

    LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                // Called when a new location is found by the GPS location
                // provider.
    
                String message = String.format(
                        "New Location \n Longitude: %1$s \n Latitude: %2$s",
                        location.getLongitude(), location.getLatitude());
                Toast.makeText(LbsGeocodingActivity.this, message,
                        Toast.LENGTH_LONG).show();
                // Here you can set your Value of Textview
    
            }
    

    I have used this in my code and it works quite well.

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

Sidebar

Related Questions

Here's the code I have. It works. The only problem is that the first
Here's a coding problem for those that like this kind of thing. Let's see
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is the code in a function I'm trying to revise. This example works
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
Here's my function: static Map AddFormation(Map _map, Tile tile, int x, int y, int
Here is my javascript code for a cursor focus function to go to username
Here is the problem that I am trying to solve. I have two folders

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.