Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Need help loading example app code
icon5.gif  Need help loading example app code [message #1427278] Sat, 20 September 2014 00:45 Go to next message
Warren Williams is currently offline Warren WilliamsFriend
Messages: 3
Registered: October 2012
Junior Member
Hello,

I found a small example of code for a GPS location app to use in Eclipse. Below is the URL of where the code is. I created a class and then pasted the code in there. I immediately got errors which you can see marked. I opened the error box for one which you can see in the screen shot attached.

Can someone tell me why I get these errors? How do I run the code from the web page? Thanks!!


Warren

GpsBasicsAndroidExample.java file

 




/***********  Create class and implements with LocationListener **************/
    public class GpsBasicsAndroidExample extends Activity implements LocationListener {
         
            private LocationManager locationManager;
             
            @Override
            protected void onCreate(Bundle savedInstanceState) {
             
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_gps_basics_android_example);
                 
                /********** get Gps location service LocationManager object ***********/
                locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                 
                /* CAL METHOD requestLocationUpdates */
                   
                  // Parameters :
                  //   First(provider)    :  the name of the provider with which to register 
                  //   Second(minTime)    :  the minimum time interval for notifications, 
                  //                         in milliseconds. This field is only used as a hint 
                  //                         to conserve power, and actual time between location 
                  //                         updates may be greater or lesser than this value. 
                  //   Third(minDistance) :  the minimum distance interval for notifications, in meters 
                  //   Fourth(listener)   :  a {#link LocationListener} whose onLocationChanged(Location) 
                  //                         method will be called for each location update 
                
                 
                locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER,
                        3000,   // 3 sec
                        10, this);
                 
                /********* After registration onLocationChanged method  ********/
                /********* called periodically after each 3 sec ***********/
            }
             
            /************* Called after each 3 sec **********/
            @Override
            public void onLocationChanged(Location location) {
                    
                String str = "Latitude: "+location.getLatitude()+" 
Longitude: "+location.getLongitude();
  
                Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
            }
         
            @Override
            public void onProviderDisabled(String provider) {
                 
                /******** Called when User off Gps *********/
                 
                Toast.makeText(getBaseContext(), "Gps turned off ", Toast.LENGTH_LONG).show();
            }
         
            @Override
            public void onProviderEnabled(String provider) {
                 
                /******** Called when User on Gps  *********/
                 
                Toast.makeText(getBaseContext(), "Gps turned on ", Toast.LENGTH_LONG).show();
            }
         
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                // TODO Auto-generated method stub
                 
            }
   }
 

  

Explanation :

 

   

                requestLocationUpdates Method :

 

                    Registers the current activity to be notified periodically by the named provider. Periodically, the supplied LocationListener will be called with the current Location or with status updates. 

        

                           Parameters :

 

                                  First(provider)           :  the name of the provider with which to register 

                                  Second(minTime)    :  the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value. 

                                   Third(minDistance)  :  the minimum distance interval for notifications, in meters 

                                    Fourth(listener)        :  a {#link LocationListener} whose onLocationChanged(Location) method will be called for each location update  

 

 

                        onLocationChanged Method :           

                                    

                                    Called after each 3 sec ( we have defined in requestLocationUpdates ).

 

                        onProviderDisabled Method :    

 

                                   Called when User off Gps in phone setting.

 

                         onProviderEnabled Method : 

 

                                    Called when User on Gps in phone setting

  • Attachment: Help1.png
    (Size: 180.78KB, Downloaded 125 times)
Re: Need help loading example app code [message #1427307 is a reply to message #1427278] Sat, 20 September 2014 01:51 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 09/19/2014 06:45 PM, Warren Williams wrote:
> Hello,
>
> I found a small example of code for a GPS location app to use in Eclipse. Below is the URL of where the code is. I created a class and then pasted the code in there. I immediately got errors which you can see marked. I opened the error box for one which you can see in the screen shot attached.
>
> Can someone tell me why I get these errors? How do I run the code from the web page? Thanks!!

Please ready sticky posts at top of forum.
Re: Need help loading example app code [message #1427353 is a reply to message #1427307] Sat, 20 September 2014 03:37 Go to previous messageGo to next message
Warren Williams is currently offline Warren WilliamsFriend
Messages: 3
Registered: October 2012
Junior Member
The only sticky note about this is maybe posting in the ADT forum. But I wasn't sure if this is specific to that or what because this is my first time using Eclipse and did not know if this meant maybe a library is not set or something like that.

Warren
Re: Need help loading example app code [message #1427640 is a reply to message #1427353] Sat, 20 September 2014 14:36 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 09/19/2014 09:37 PM, Warren Williams wrote:
> The only sticky note about this is maybe posting in the ADT forum. But I
> wasn't sure if this is specific to that or what because this is my first
> time using Eclipse and did not know if this meant maybe a library is not
> set or something like that.
>
> Warren

Yeah, your illustration tells me that you're having trouble piecing
together this Android application.

First, if Activity is missing, it's something with how you have or
haven't integrated ADT libraries. I've done a bit of Android programming
(albeit long ago) and I know that this is a class you can't get around
dealing with no matter how simple or tiny your application is.

Second, the question of how to run the code from the web page is hard
for me to understand. You should be asking how to run the code from
Eclipse? Did you mean the code you took from the webpage and pasted into
Eclipse? Etc. However, the answer likely lies somewhere between whoever
is supporting the webpage example and folk in an ADT forum.

Lars Vogella probably has some great Android aids on his website
(http://www.vogella.com/tutorials/android.html) although they've changed
hugely since I used them over 4 years ago.

The point of the forum sticky posts isn't to be rude, but as you read,
we can't extend the breadth of Eclipse fora to cover frameworks that
consume Eclipse, that may change all the time, etc., but aren't from the
narrower Eclipse IDE community.

There are many examples of frameworks that are supported by Eclipse
fora; and many, like ADT, that aren't properly Eclipse. It's
understandably confusing.

Best of luck.
Previous Topic:Need help with my eclipse Juno IDE
Next Topic:Cannot "find" or run project downloaded from Github
Goto Forum:
  


Current Time: Thu Apr 25 00:35:55 GMT 2024

Powered by FUDForum. Page generated in 0.10256 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top