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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:51:33+00:00 2026-05-31T07:51:33+00:00

I want to get the value of current location. I use this code but

  • 0

I want to get the value of current location. I use this code but I just obtain this message “Waiting for location update…”. There is a configuraition should I make it in the phone to get the adress of current location???
The GPS status is available of my mobile. But I think the location is not valid because I didn’t get the alert dialog. What should do to get the latitude and longitude of current location ??

package mypackage;

import net.rim.device.api.gps.*;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import javax.microedition.location.*;

public class MultipleFixDemo extends UiApplication 
{    
    private static int _interval = 1;
    private EditField _status;    

    public static void main(String[] args)
    {
        new MultipleFixDemo().enterEventDispatcher();
    }

    public MultipleFixDemo()
    {
        MultipleFixScreen screen = new MultipleFixScreen();
        screen.setTitle("Multiple Fix Demo");

        _status = new EditField(Field.NON_FOCUSABLE);
        screen.add(_status);

        startLocationUpdate();
        pushScreen(screen);
    }

    private void updateLocationScreen(final String msg)
    {
        invokeLater(new Runnable()
        {
            public void run()
            {
                _status.setText(msg);
            }
        });
    }

   private void startLocationUpdate()
    {
        try
        {
            BlackBerryCriteria myCriteria = new BlackBerryCriteria();
            myCriteria.enableGeolocationWithGPS();
            try
            {
                BlackBerryLocationProvider myProvider = (BlackBerryLocationProvider)LocationProvider.getInstance(myCriteria);

                if ( myProvider == null )
                {
                    Runnable showUnsupportedDialog = new Runnable() 
                    {
                        public void run() {
                            Dialog.alert("Location service unsupported, exiting...");
                            System.exit( 1 );
                        }
                    };
                    invokeLater( showUnsupportedDialog );  
                }
                else
                {
                    myProvider.setLocationListener(new LocationListenerImpl(), _interval, 1, 1);

                }
            }
            catch (LocationException le)
            {
                System.err.println("Failed to retrieve a location provider");
                System.err.println(le); 
                System.exit(0);
            }
        }
        catch (UnsupportedOperationException ue)
        {
            System.err.println("Require mode is unavailable");
            System.err.println(ue); 
            System.exit(0);   
        }
        return;
    }


    private class LocationListenerImpl implements LocationListener
    {
        public void locationUpdated(LocationProvider provider, Location location)
        {
            if(location.isValid())

            {
                Dialog.alert("if");
                double longitude = location.getQualifiedCoordinates().getLongitude();
                double latitude = location.getQualifiedCoordinates().getLatitude();
                float altitude = location.getQualifiedCoordinates().getAltitude();

                StringBuffer sb = new StringBuffer();
                sb.append("Longitude: ");
                sb.append(longitude);
                sb.append("\n");
                sb.append("Latitude: ");
                sb.append(latitude);
                sb.append("\n");
                sb.append("Altitude: ");
                sb.append(altitude);
                sb.append(" m");
                MultipleFixDemo.this.updateLocationScreen(sb.toString());
            }
        }

        public void providerStateChanged(LocationProvider provider, int newState)
        {
            // Not implemented
        }        
    }

    private final static class MultipleFixScreen extends MainScreen
    {
        MultipleFixScreen()
        {
            super(DEFAULT_CLOSE | DEFAULT_MENU);

            RichTextField instructions = new RichTextField("Waiting for location update...",Field.NON_FOCUSABLE);
            this.add(instructions);
        }
    }     
}
  • 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-31T07:51:33+00:00Added an answer on May 31, 2026 at 7:51 am

    Try this code it will work for me. it will give lat and long every 1 sec with update.

    import javax.microedition.location.Location;
    import javax.microedition.location.LocationException;
    import javax.microedition.location.LocationListener;
    import javax.microedition.location.LocationProvider;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.component.RichTextField;
    import net.rim.device.api.ui.container.MainScreen;
    
    
    public final class MyScreen extends MainScreen
    {
         private LocationProvider locationProvider;
         private static int interval = 1;
         double lat;
         double longt;
    
        public MyScreen()
        {   
            setTitle("MyTitle");
            startLocationUpdate();          
        }
    
        private boolean startLocationUpdate()
        {
            boolean retval = false;
    
                try
                {
                locationProvider = LocationProvider.getInstance(null);
    
                if ( locationProvider == null )
                {
    
                Runnable showGpsUnsupportedDialog = new Runnable()
                {
                    public void run()
                    {
    
                    Dialog.alert("GPS is not supported on this platform, exiting...");
                    //System.exit( 1 );
                    }
                };
    
                UiApplication.getUiApplication().invokeAndWait( showGpsUnsupportedDialog ); // Ask event-dispatcher thread to display dialog ASAP.
                }
                else
                {
    
                locationProvider.setLocationListener(new LocationListenerImpl(), interval, 1, 1);
    
                retval = true;
                }
                }
                catch (LocationException le)
                {
                    System.err.println("Failed to instantiate the LocationProvider object, exiting...");
                    System.err.println(le);
                    System.exit(0);
                }
                return retval;
                }
    
                private class LocationListenerImpl implements LocationListener
                {
    
                public void locationUpdated(LocationProvider provider, Location location)
                {
                        if(location.isValid())
                        {
                            double longitude = location.getQualifiedCoordinates().getLongitude();
                            double latitude = location.getQualifiedCoordinates().getLatitude();
    
                            updateLocationScreen(latitude, longitude);              
    
                        }
                }
    
                public void providerStateChanged(LocationProvider provider, int newState)
                {
                }
            }
    
             private void updateLocationScreen(final double latitude, final double longitude)
                {
                        UiApplication.getUiApplication().invokeAndWait(new Runnable()
                        {
                        public void run()
                        {
                        lat = latitude;
                        longt = longitude;
    
    
                        RichTextField txt=new RichTextField();
                        txt.setText("Long=="+longt);
    
                        RichTextField txt1=new RichTextField();
                        txt1.setText("lat=="+lat);
    
                        add(txt);
                        add(txt1);
    
    
    //                  persistentLatitude.setContents(Double.toString(latitude));
    //                  persistentLongitude.setContents(Double.toString(longitude));
    
    
    
                        }
                        });
                }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I simply want to get the current value of a field's attribute. This field
I want to get zip code from users current location(Latitude, Longitude), I had used
I want to use the DateTime.TryParse method to get the datetime value of a
I want to be able to get the current location of the mouse pointer,
I am trying to get current location of user using CLLocationCoordinate2D. I want the
I want to get the current value of the EIP register with assembly language.
I want to get the value of my integer array, at an index. The
Suppose I have a XmlNode and I want to get the value of an
i have put fckeditor in jsp page. I want to get the value whatever
I want to get the ASCII value of characters in a string in C#.

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.