diff options
author | sjtufs <[email protected]> | 2013-08-22 10:02:04 +0800 |
---|---|---|
committer | sjtufs <[email protected]> | 2013-08-22 10:02:04 +0800 |
commit | 21fa4ac31533424dce71fbb2e49171f7bff167f7 (patch) | |
tree | 77471088c7c9ee16147964e6098f44fee3f84600 /client/gps-demo | |
parent | 7f70b8fef4445f605d865e6640669541afa696a1 (diff) |
gps demo
Diffstat (limited to 'client/gps-demo')
38 files changed, 457 insertions, 0 deletions
diff --git a/client/gps-demo/AndroidGPSTracking/.AndroidManifest.xml.swp b/client/gps-demo/AndroidGPSTracking/.AndroidManifest.xml.swp Binary files differnew file mode 100644 index 0000000..d03b360 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/.AndroidManifest.xml.swp diff --git a/client/gps-demo/AndroidGPSTracking/.classpath b/client/gps-demo/AndroidGPSTracking/.classpath new file mode 100644 index 0000000..5176974 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/.classpath @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> + <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> + <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="gen"/> + <classpathentry kind="output" path="bin/classes"/> +</classpath> diff --git a/client/gps-demo/AndroidGPSTracking/.project b/client/gps-demo/AndroidGPSTracking/.project new file mode 100644 index 0000000..a080853 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>AndroidGPSTracking</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/client/gps-demo/AndroidGPSTracking/.settings/org.eclipse.jdt.core.prefs b/client/gps-demo/AndroidGPSTracking/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b080d2d --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/client/gps-demo/AndroidGPSTracking/AndroidManifest.xml b/client/gps-demo/AndroidGPSTracking/AndroidManifest.xml new file mode 100644 index 0000000..137894c --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/AndroidManifest.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.gpstracking"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="8" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:name=".AndroidGPSTrackingActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.INTERNET" />
+
+</manifest>
\ No newline at end of file diff --git a/client/gps-demo/AndroidGPSTracking/bin/AndroidGPSTracking.apk b/client/gps-demo/AndroidGPSTracking/bin/AndroidGPSTracking.apk Binary files differnew file mode 100644 index 0000000..985304a --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/AndroidGPSTracking.apk diff --git a/client/gps-demo/AndroidGPSTracking/bin/AndroidManifest.xml b/client/gps-demo/AndroidGPSTracking/bin/AndroidManifest.xml new file mode 100644 index 0000000..137894c --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/AndroidManifest.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.gpstracking"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="8" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:name=".AndroidGPSTrackingActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.INTERNET" />
+
+</manifest>
\ No newline at end of file diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes.dex b/client/gps-demo/AndroidGPSTracking/bin/classes.dex Binary files differnew file mode 100644 index 0000000..1a8d494 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes.dex diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/AndroidGPSTrackingActivity$1.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/AndroidGPSTrackingActivity$1.class Binary files differnew file mode 100644 index 0000000..3367336 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/AndroidGPSTrackingActivity$1.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/AndroidGPSTrackingActivity.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/AndroidGPSTrackingActivity.class Binary files differnew file mode 100644 index 0000000..7df00e1 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/AndroidGPSTrackingActivity.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/BuildConfig.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/BuildConfig.class Binary files differnew file mode 100644 index 0000000..15960aa --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/BuildConfig.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker$1.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker$1.class Binary files differnew file mode 100644 index 0000000..8e2ea2b --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker$1.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker$2.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker$2.class Binary files differnew file mode 100644 index 0000000..572f305 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker$2.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker.class Binary files differnew file mode 100644 index 0000000..6f6bd93 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/GPSTracker.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$attr.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$attr.class Binary files differnew file mode 100644 index 0000000..1dbe417 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$attr.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$drawable.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$drawable.class Binary files differnew file mode 100644 index 0000000..f46f86d --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$drawable.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$id.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$id.class Binary files differnew file mode 100644 index 0000000..7d48158 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$id.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$layout.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$layout.class Binary files differnew file mode 100644 index 0000000..08f0ade --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$layout.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$string.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$string.class Binary files differnew file mode 100644 index 0000000..7c72195 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R$string.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R.class b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R.class Binary files differnew file mode 100644 index 0000000..7f0475e --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/classes/com/example/gpstracking/R.class diff --git a/client/gps-demo/AndroidGPSTracking/bin/dexedLibs/annotations-5b022f4578500e25e3bfa446659bd7d8.jar b/client/gps-demo/AndroidGPSTracking/bin/dexedLibs/annotations-5b022f4578500e25e3bfa446659bd7d8.jar Binary files differnew file mode 100644 index 0000000..61505d5 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/dexedLibs/annotations-5b022f4578500e25e3bfa446659bd7d8.jar diff --git a/client/gps-demo/AndroidGPSTracking/bin/jarlist.cache b/client/gps-demo/AndroidGPSTracking/bin/jarlist.cache new file mode 100644 index 0000000..0565465 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/jarlist.cache @@ -0,0 +1,3 @@ +# cache for current jar dependency. DO NOT EDIT. +# format is <lastModified> <length> <SHA-1> <path> +# Encoding is UTF-8 diff --git a/client/gps-demo/AndroidGPSTracking/bin/res/drawable-hdpi/ic_launcher.png b/client/gps-demo/AndroidGPSTracking/bin/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..882eb14 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/res/drawable-hdpi/ic_launcher.png diff --git a/client/gps-demo/AndroidGPSTracking/bin/res/drawable-ldpi/ic_launcher.png b/client/gps-demo/AndroidGPSTracking/bin/res/drawable-ldpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..18689f6 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/res/drawable-ldpi/ic_launcher.png diff --git a/client/gps-demo/AndroidGPSTracking/bin/res/drawable-mdpi/ic_launcher.png b/client/gps-demo/AndroidGPSTracking/bin/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..02e96b9 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/res/drawable-mdpi/ic_launcher.png diff --git a/client/gps-demo/AndroidGPSTracking/bin/resources.ap_ b/client/gps-demo/AndroidGPSTracking/bin/resources.ap_ Binary files differnew file mode 100644 index 0000000..8c035b7 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/bin/resources.ap_ diff --git a/client/gps-demo/AndroidGPSTracking/default.properties b/client/gps-demo/AndroidGPSTracking/default.properties new file mode 100644 index 0000000..32299c2 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/default.properties @@ -0,0 +1,2 @@ +# Project target. +target=android-8 diff --git a/client/gps-demo/AndroidGPSTracking/gen/com/example/gpstracking/BuildConfig.java b/client/gps-demo/AndroidGPSTracking/gen/com/example/gpstracking/BuildConfig.java new file mode 100644 index 0000000..c164cb3 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/gen/com/example/gpstracking/BuildConfig.java @@ -0,0 +1,6 @@ +/** Automatically generated file. DO NOT MODIFY */ +package com.example.gpstracking; + +public final class BuildConfig { + public final static boolean DEBUG = true; +}
\ No newline at end of file diff --git a/client/gps-demo/AndroidGPSTracking/gen/com/example/gpstracking/R.java b/client/gps-demo/AndroidGPSTracking/gen/com/example/gpstracking/R.java new file mode 100644 index 0000000..c747309 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/gen/com/example/gpstracking/R.java @@ -0,0 +1,26 @@ +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package com.example.gpstracking; + +public final class R { + public static final class attr { + } + public static final class drawable { + public static final int ic_launcher=0x7f020000; + } + public static final class id { + public static final int btnShowLocation=0x7f050000; + } + public static final class layout { + public static final int main=0x7f030000; + } + public static final class string { + public static final int app_name=0x7f040001; + public static final int hello=0x7f040000; + } +} diff --git a/client/gps-demo/AndroidGPSTracking/proguard.cfg b/client/gps-demo/AndroidGPSTracking/proguard.cfg new file mode 100644 index 0000000..b1cdf17 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/proguard.cfg @@ -0,0 +1,40 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native <methods>; +} + +-keepclasseswithmembers class * { + public <init>(android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public <init>(android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/client/gps-demo/AndroidGPSTracking/project.properties b/client/gps-demo/AndroidGPSTracking/project.properties new file mode 100644 index 0000000..ea89160 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/project.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-8 diff --git a/client/gps-demo/AndroidGPSTracking/res/drawable-hdpi/ic_launcher.png b/client/gps-demo/AndroidGPSTracking/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..8074c4c --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/res/drawable-hdpi/ic_launcher.png diff --git a/client/gps-demo/AndroidGPSTracking/res/drawable-ldpi/ic_launcher.png b/client/gps-demo/AndroidGPSTracking/res/drawable-ldpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..1095584 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/res/drawable-ldpi/ic_launcher.png diff --git a/client/gps-demo/AndroidGPSTracking/res/drawable-mdpi/ic_launcher.png b/client/gps-demo/AndroidGPSTracking/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..a07c69f --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/res/drawable-mdpi/ic_launcher.png diff --git a/client/gps-demo/AndroidGPSTracking/res/layout/main.xml b/client/gps-demo/AndroidGPSTracking/res/layout/main.xml new file mode 100644 index 0000000..430efa2 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/res/layout/main.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <Button android:id="@+id/btnShowLocation"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Show Location"
+ android:layout_centerVertical="true"
+ android:layout_centerHorizontal="true"/>
+
+</RelativeLayout>
\ No newline at end of file diff --git a/client/gps-demo/AndroidGPSTracking/res/values/strings.xml b/client/gps-demo/AndroidGPSTracking/res/values/strings.xml new file mode 100644 index 0000000..6c854c3 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/res/values/strings.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Hello World, AndroidGPSTrackingActivity!</string>
+ <string name="app_name">AndroidGPSTracking</string>
+
+</resources>
\ No newline at end of file diff --git a/client/gps-demo/AndroidGPSTracking/src/com/example/gpstracking/AndroidGPSTrackingActivity.java b/client/gps-demo/AndroidGPSTracking/src/com/example/gpstracking/AndroidGPSTrackingActivity.java new file mode 100644 index 0000000..cdc1413 --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/src/com/example/gpstracking/AndroidGPSTrackingActivity.java @@ -0,0 +1,50 @@ +package com.example.gpstracking; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +public class AndroidGPSTrackingActivity extends Activity { + + Button btnShowLocation; + + // GPSTracker class + GPSTracker gps; + + @Override + public void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + btnShowLocation = (Button) findViewById(R.id.btnShowLocation); + + // show location button click event + btnShowLocation.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View arg0) { + // create class object + gps = new GPSTracker(AndroidGPSTrackingActivity.this); + + // check if GPS enabled + if(gps.canGetLocation()){ + + double latitude = gps.getLatitude(); + double longitude = gps.getLongitude(); + + Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show(); + }else{ + // can't get location + // GPS or Network is not enabled + // Ask user to enable GPS/network in settings + gps.showSettingsAlert(); + } + + } + }); + } + +}
\ No newline at end of file diff --git a/client/gps-demo/AndroidGPSTracking/src/com/example/gpstracking/GPSTracker.java b/client/gps-demo/AndroidGPSTracking/src/com/example/gpstracking/GPSTracker.java new file mode 100644 index 0000000..f1e77ad --- /dev/null +++ b/client/gps-demo/AndroidGPSTracking/src/com/example/gpstracking/GPSTracker.java @@ -0,0 +1,200 @@ +package com.example.gpstracking;
+
+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;
+import android.util.Log;
+
+public class GPSTracker extends Service implements LocationListener {
+
+ private final Context mContext;
+
+ // flag for GPS status
+ boolean isGPSEnabled = false;
+
+ // flag for network status
+ boolean isNetworkEnabled = false;
+
+ // flag for GPS status
+ boolean canGetLocation = false;
+
+ Location location; // location
+ double latitude; // latitude
+ double longitude; // longitude
+
+ // The minimum distance to change Updates in meters
+ private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
+
+ // The minimum time between updates in milliseconds
+ private static final long MIN_TIME_BW_UPDATES = 10 * 60 * 1; // 1 minute
+
+ // Declaring a Location Manager
+ protected LocationManager locationManager;
+
+ public GPSTracker(Context context) {
+ this.mContext = context;
+ getLocation();
+ }
+
+ public Location getLocation() {
+ try {
+ locationManager = (LocationManager) mContext
+ .getSystemService(LOCATION_SERVICE);
+
+ // getting GPS status
+ isGPSEnabled = locationManager
+ .isProviderEnabled(LocationManager.GPS_PROVIDER);
+
+ // getting network status
+ isNetworkEnabled = locationManager
+ .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
+
+ if (!isGPSEnabled && !isNetworkEnabled) {
+ // no network provider is enabled
+ } else {
+ this.canGetLocation = true;
+ if (isNetworkEnabled) {
+ locationManager.requestLocationUpdates(
+ LocationManager.NETWORK_PROVIDER,
+ MIN_TIME_BW_UPDATES,
+ MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
+ Log.d("Network", "Network");
+ if (locationManager != null) {
+ location = locationManager
+ .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+ if (location != null) {
+ latitude = location.getLatitude();
+ longitude = location.getLongitude();
+ }
+ }
+ }
+ // if GPS Enabled get lat/long using GPS Services
+ if (isGPSEnabled) {
+ if (location == null) {
+ locationManager.requestLocationUpdates(
+ LocationManager.GPS_PROVIDER,
+ MIN_TIME_BW_UPDATES,
+ MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
+ Log.d("GPS Enabled", "GPS Enabled");
+ if (locationManager != null) {
+ location = locationManager
+ .getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ if (location != null) {
+ latitude = location.getLatitude();
+ longitude = location.getLongitude();
+ }
+ }
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return location;
+ }
+
+ /**
+ * Stop using GPS listener
+ * Calling this function will stop using GPS in your app
+ */
+ public void stopUsingGPS(){
+ if(locationManager != null){
+ locationManager.removeUpdates(GPSTracker.this);
+ }
+ }
+
+ /**
+ * Function to get latitude
+ */
+ public double getLatitude(){
+ if(location != null){
+ latitude = location.getLatitude();
+ }
+
+ // return latitude
+ return latitude;
+ }
+
+ /**
+ * Function to get longitude
+ */
+ public double getLongitude(){
+ if(location != null){
+ longitude = location.getLongitude();
+ }
+
+ // return longitude
+ return longitude;
+ }
+
+ /**
+ * Function to check GPS/wifi enabled
+ * @return boolean
+ */
+ public boolean canGetLocation() {
+ return this.canGetLocation;
+ }
+
+ /**
+ * Function to show settings alert dialog
+ * On pressing Settings button will lauch Settings Options
+ */
+ public void showSettingsAlert(){
+ AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
+
+ // Setting Dialog Title
+ alertDialog.setTitle("GPS is settings");
+
+ // Setting Dialog Message
+ alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
+
+ // On pressing Settings button
+ alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,int which) {
+ Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+ mContext.startActivity(intent);
+ }
+ });
+
+ // on pressing cancel button
+ alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ });
+
+ // Showing Alert Message
+ alertDialog.show();
+ }
+
+ @Override
+ public void onLocationChanged(Location location) {
+ }
+
+ @Override
+ public void onProviderDisabled(String provider) {
+ }
+
+ @Override
+ public void onProviderEnabled(String provider) {
+ }
+
+ @Override
+ public void onStatusChanged(String provider, int status, Bundle extras) {
+ }
+
+ @Override
+ public IBinder onBind(Intent arg0) {
+ return null;
+ }
+}
|