×

Discussion Board

Results 1 to 4 of 4

Threaded View

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    21

    problem in getting loaction from location api

    i want find find my application's location using location API. but i am getting null location:
    here is my code snippet


    Code:
    public void startGPS() 
    	{
             if (locationProvider == null) 
    		{
                createLocationProvider();
    
                locationThread = new Thread() 
    			{
                    public void run()
    				{
                            	createLocationListener();           	
    				}
                };
                locationThread.start();
           	}       
        } 
    	private void createLocationProvider() 
    	{
            Criteria cr = new Criteria(); 
            try 
    		{
                	locationProvider = LocationProvider.getInstance(cr);
            } 
    		catch (Exception e) 
    		{
               	midlet.log("GPS.createLocationProvider: " + e);
            }
        }
    public void providerStateChanged(LocationProvider provider, int newState) {}
    	private void createLocationListener()
    	{
              // 2cd value is interval in seconds
    		try 
    		{
                	locationProvider.setLocationListener(this, 60, -1, -1); 
            } 
    		catch (Exception e) 
    		{
               	midlet.log("GPS.createLocationListener: " + e);
            } 	
       	}
        private void getLocation(Location location)
    	{
            try 
    		{	
            	
            	QualifiedCoordinates qualifiedCoordinates=location.getQualifiedCoordinates();
            	if(qualifiedCoordinates!=null)
            	{
            		lat=qualifiedCoordinates.getLatitude();
            		lon=qualifiedCoordinates.getLongitude();
            		midlet.sendloc(lat, lon);
            	}else
            	{
            		midlet.log("Coordinates are null!");
            	}
    		}
            catch (Exception e) 
            {
                midlet.log("GPS.getLocation: " + e);
            }
    	}
        public void locationUpdated(LocationProvider provider, final Location location) 
        {
            // get new location from locationProvider
             
            try 
            {
            		Thread getLocationThread = new Thread()
            		{
            			public void run()
            			{
            				getLocation(location);
            			}	
                    };getLocationThread.start();
            } 
            catch (Exception e) 
            {
               midlet.log("GPS.locationUpdated: " + e);
            }
        }
    Last edited by wizard_hu_; 2013-03-25 at 10:08. Reason: [CODE][/CODE] - unfortunately the indents uses both spaces and tabs...

Similar Threads

  1. Problem Location.
    By aeramcm in forum Mobile Java General
    Replies: 2
    Last Post: 2010-10-13, 17:45
  2. Problem in Getting Location.....
    By furqankamani in forum Symbian
    Replies: 2
    Last Post: 2009-06-11, 08:57
  3. Location API Problem
    By martinsjulio in forum Mobile Java General
    Replies: 3
    Last Post: 2008-09-07, 22:02
  4. Location API Problem
    By sandeepsandeep in forum Mobile Java General
    Replies: 1
    Last Post: 2008-08-27, 15:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •