0% found this document useful (0 votes)
6 views6 pages

Mobile Computing 4

Uploaded by

rashsarvade02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Mobile Computing 4

Uploaded by

rashsarvade02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Assignment No.

Problem Statement : Develop a native application that uses GPS location information.

<?xml version="1.0" encoding="utf-8"?>

<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.Context; import android.content.DialogInterface;

import android.content.Intent;

import android.location.Location;

import android.location.LocationListener;

import android.location.LocationManager;

import android.os.Bundle; import android.os.IBinder;

import android.provider.Settings;

public class GPStrace extends Service implements LocationListener{

private final Context context;

boolean isGPSEnabled=false;

boolean canGetLocation-false;

boolean isNetworkEnabled=false;

Location location:

double latitude:

double longtitude;

private static final long

MIN DISTANCE CHANGE FOR UPDATES-10;

private static final long MIN_TIME_BW_UPDATES-1000*60*1;

protected LocationManager locationManager:

public GPStrace (Context context)

this.context=context; getLocation();

public Location getLocation()

{
try{ locationManager=(LocationManager) context.getSystemService(LOCATION_SERVICE);

isGPSEnabled=locationManager.isProviderEnabled (Location Manager.GPS PROVIDER);

isNetworkEnabled=locationManager.isProviderEnabled (Locat ionManager.NETWORK PROVIDER);

if (!isGPSEnabled && !isNetworkEnabled) (

}else{

this.canGetLocation=true;

if(isNetworkEnabled) { locationManager.requestLocationUpdates ( LocationManager.NETWORK


PROVIDER, MIN

TIME BW UPDATES,

MIN DISTANCE CHANGE FOR UPDATES,this);

if(locationManager!=null){

location=locationManager.getLast KnownLocation (LocationMa nager.NETWORK PROVIDER);

if(location!=null)(

latitude=location.getLatitude();

longtitude-location.getLongitude();

if(isGPSEnabled) (

if(location==null){

locationManager.requestLocationUpdates (LocationManager.G

PS_PROVIDER, MIN_TIME_BW_UPDATES, MIN DISTANCE CHANGE FOR UPDATES, this);

if (locationManager!=null){

location=locationManager.getLastKnownLocation (LocationMa nager.GPS_PROVIDER);

if (location!=null) {

latitude-location.getLatitude();

longtitude=location.getLongitude();

catch (Exception e)

e.printStackTrace();
return location;

public void stopUsingGPS () {

if (locationManager!=null) {

locationManager.removeUpdates (GPStrace.this);

public double getLatitude () {

if (location!=null){

latitude=location.getLatitude();

return latitude;

public double getLongtiude(){

if (location!=null) (

longtitude=location.getLatitude();

} return longtitude;

public boolean canGetLocation()(

return this.canGetLocation:

public void showSettingAlert(){

AlertDialog.Builder alertDialog=new AlertDialog.Builder(context);

alertDialog.setTitle("GPS is settings");

alertDialog.setMessage("GPS is not enabled. Do you want to go to setting menu?");

alertDialog.setPositiveButton("settings", new

DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int

which) (

Intent intent-new

Intent (Settings.ACTION LOCATION SOURCE SETTINGS); context.startActivity(intent);

});
alertDialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int

which) {

// TODO Auto-generated method stub dialog.cancel();

alertDialog.show();

@Override

public void onLocationChanged (Location location) (

// TODO Auto-generated method stub

@Override

public void onProviderDisabled(String provider) ( // TODO Auto-generated method stub

@Override

public void onProviderEnabled(String provider) (

// TODO Auto-generated method stub

@Override

public void onStatusChanged (String provider, int status,

Bundle extras) f

// TODO Auto-generated method stub

@override

public Binder onBind(Intent intent)

// TODO Auto-generated method stub

return null

}
}

You might also like