warrenwsav
Lurker
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. Well, it won't let me post links or images as a new user. The word Activity and LocationManager in the function line is highlited as an error as many others in the code.
Can someone tell me why I get these errors? How do I run the code from the web page? Thanks!!
Warren
[HIGH]
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
[/HIGH]
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. Well, it won't let me post links or images as a new user. The word Activity and LocationManager in the function line is highlited as an error as many others in the code.
Can someone tell me why I get these errors? How do I run the code from the web page? Thanks!!
Warren
[HIGH]
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
[/HIGH]