Mobile Computing 4
Mobile Computing 4
Problem Statement : Develop a native application that uses GPS location information.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/show_Location"
android:layout width="wrap_content"
android:layout height="wrap_content"
android:text="Show_Location"
android:layout_centerVertical="true"
android:layout centerHorizontal="true"/>
</RelativeLayout>
Select the GPStrace.java file and paste the following code.
package gps.location;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.provider.Settings;
boolean isGPSEnabled=false;
boolean canGetLocation-false;
boolean isNetworkEnabled=false;
Location location:
double latitude:
double longtitude;
this.context=context; getLocation();
{
try{ locationManager=(LocationManager) context.getSystemService(LOCATION_SERVICE);
}else{
this.canGetLocation=true;
TIME BW UPDATES,
if(locationManager!=null){
if(location!=null)(
latitude=location.getLatitude();
longtitude-location.getLongitude();
if(isGPSEnabled) (
if(location==null){
locationManager.requestLocationUpdates (LocationManager.G
if (locationManager!=null){
if (location!=null) {
latitude-location.getLatitude();
longtitude=location.getLongitude();
catch (Exception e)
e.printStackTrace();
return location;
if (locationManager!=null) {
locationManager.removeUpdates (GPStrace.this);
if (location!=null){
latitude=location.getLatitude();
return latitude;
if (location!=null) (
longtitude=location.getLatitude();
} return longtitude;
return this.canGetLocation:
alertDialog.setTitle("GPS is settings");
alertDialog.setPositiveButton("settings", new
DialogInterface.OnClickListener() {
@Override
which) (
Intent intent-new
});
alertDialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
which) {
alertDialog.show();
@Override
@Override
@Override
@Override
Bundle extras) f
@override
return null
}
}