Loading...
Loading...
Loading...
Loading...

Android - Simple GPS Location

View: 294    Dowload: 0   Comment: 0   Post by: daii   Category: Mobile applications   Fields: Game - Entertainment

Download  android-simple-gps-location.zip (412.01 KB)

You need to Sign In to download the file android-simple-gps-location.zip
If you do not have an account then Sign up for free here

In this tutorial we will try to create a Simple GPS Location using Android. This simple application can be used to any system that needed the information about the location of the user. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any devices such as TV, phones, watches etc. So now let's do the coding.....

Getting Started:

First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things.

Here's the link for the Android Studio https://developer.android.com/studio/index.html.

Layout Design

We will now create the design for the application, first locate the layout file called activity_main.xml, this is the default name when create a new activity. Then write these codes inside your layout file.


 
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> xmlns:app="<a href="http://schemas.android.com/apk/res-auto"
  5. " rel="nofollow">http://schemas.android.com/apk/res-auto"
  6. </a> xmlns:tools="<a href="http://schemas.android.com/tools"
  7. " rel="nofollow">http://schemas.android.com/tools"
  8. </a> android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. tools:context="com.razormist.simplegpslocation.MainActivity">
  11.  
  12.  
  13.  
  14. android:id="@+id/btn_locate"
  15. android:layout_height="wrap_content"
  16. android:layout_width="wrap_content"
  17. android:layout_centerInParent="true"
  18. android:text="Locate"/>
  19.  
  20. <TextView
  21. android:id="@+id/textView"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:text="Latitude:"
  25. android:textSize="20sp"
  26. android:layout_marginRight="100dp"
  27. android:layout_marginEnd="100dp"
  28. android:layout_marginBottom="63dp"
  29. android:layout_above="@+id/btn_locate"
  30. android:layout_alignRight="@+id/btn_locate"
  31. android:layout_alignEnd="@+id/btn_locate" />
  32.  
  33. <TextView
  34. android:id="@+id/tv_latitude"
  35. android:textSize="20sp"
  36. android:layout_width="wrap_content"
  37. android:layout_height="wrap_content"
  38. android:layout_alignLeft="@+id/btn_locate"
  39. android:layout_alignStart="@+id/btn_locate"
  40. android:layout_alignTop="@+id/textView" />
  41.  
  42.  
  43. <TextView
  44. android:id="@+id/textView1"
  45. android:layout_width="wrap_content"
  46. android:layout_height="wrap_content"
  47. android:text="Longhitud:"
  48. android:textSize="20sp"
  49. android:layout_below="@+id/tv_latitude"
  50. android:layout_alignRight="@+id/textView"
  51. android:layout_alignEnd="@+id/textView"
  52. android:layout_marginTop="16dp" />
  53.  
  54. <TextView
  55. android:id="@+id/tv_longhitud"
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:textSize="20sp"
  59. android:layout_alignBaseline="@+id/textView1"
  60. android:layout_alignBottom="@+id/textView1"
  61. android:layout_alignLeft="@+id/tv_latitude"
  62. android:layout_alignStart="@+id/tv_latitude" />
  63.  
  64.  
  65. </RelativeLayout>

Android Manifest File

The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code. It describe the overall information about the application. It contains some libraries that needed to access the several method within the app.


 
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> package="com.razormist.simplegpslocation">
  5.  
  6. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  7.  
  8. <application
  9. android:allowBackup="true"
  10. android:icon="@mipmap/ic_launcher"
  11. android:label="@string/app_name"
  12. android:roundIcon="@mipmap/ic_launcher_round"
  13. android:supportsRtl="true"
  14. android:theme="@style/AppTheme">
  15. <activity android:name=".MainActivity"
  16. android:configChanges="orientation"
  17. android:screenOrientation="portrait">
  18. <intent-filter>
  19. <action android:name="android.intent.action.MAIN" />
  20.  
  21. <category android:name="android.intent.category.LAUNCHER" />
  22. </intent-filter>
  23. </activity>
  24. </application>
  25. </manifest>

Creating the GPS Locator

This code contains the script for the GPS. This code will access the device GPS to get the information about the actual location of the device. To do that create a new java class called GPSLocator then write these block of codes inside of it.


 
  1. package com.razormist.simplegpslocation;
  2.  
  3. import android.Manifest;
  4. import android.content.Context;
  5. import android.content.pm.PackageManager;
  6. import android.location.Location;
  7. import android.location.LocationListener;
  8. import android.location.LocationManager;
  9. import android.os.Bundle;
  10. import android.support.v4.content.ContextCompat;
  11. import android.widget.Toast;
  12.  
  13. /**
  14.  * Created by Arvin on 4/5/2018.
  15.  */
  16.  
  17. public class GPSLocator implements LocationListener {
  18. Context context;
  19.  
  20. public GPSLocator(Context c){
  21. context = c;
  22. }
  23.  
  24. public Location GetLocation(){
  25. if(ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
  26. Toast.makeText(context, "Permission not granted", Toast.LENGTH_SHORT).show();
  27. return null;
  28. }
  29.  
  30. LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  31. boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  32. if(isGPSEnabled){
  33. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 6000, 10, this);
  34. Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  35. return location;
  36. }else{
  37. Toast.makeText(context, "No GPS Detected", Toast.LENGTH_SHORT).show();
  38. }
  39.  
  40. return null;
  41. }
  42.  
  43. @Override
  44. public void onLocationChanged(Location location) {
  45.  
  46. }
  47.  
  48. @Override
  49. public void onStatusChanged(String provider, int status, Bundle extras) {
  50.  
  51. }
  52.  
  53. @Override
  54. public void onProviderEnabled(String provider) {
  55.  
  56. }
  57.  
  58. @Override
  59. public void onProviderDisabled(String provider) {
  60.  
  61. }
  62.  
  63.  
  64. }

The Main Function

This code contains the main function of the application. This code will start gathering the data that has been locate through the device GPS and display the result when the button is clicked. To start with first locate your MainActivity java file and open it, then write these variable inside the MainActivity class.


 
  1. Button btn_locate;
  2. TextView tv_latitude, tv_longhitud;

Finally, initialize the require methods inside the onCreate method to run the application.


 
  1. btn_locate = (Button)findViewById(R.id.btn_locate);
  2. tv_latitude = (TextView)findViewById(R.id.tv_latitude);
  3. tv_longhitud = (TextView)findViewById(R.id.tv_longhitud);
  4.  
  5. ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 123);
  6. btn_locate.setOnClickListener(new View.OnClickListener() {
  7. @Override
  8. public void onClick(View v) {
  9. GPSLocator gpsLocator = new GPSLocator(getApplicationContext());
  10. Location location = gpsLocator.GetLocation();
  11. if(location != null){
  12. double latitude = location.getLatitude();
  13. double longhitud = location.getLongitude();
  14. tv_latitude.setText(String.valueOf(latitude));
  15. tv_longhitud.setText(String.valueOf(longhitud));
  16. }
  17. }
  18. });

Try to run the app and see if it worked.

There you have it we have created a Simple GPS Location using Android. I hope that this tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Android - Simple GPS Location

Learn on how to create a Simple GPS Location using Android. This simple application can be used to any system that needed the information about the location of the user. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any devices such as TV, phones, watches etc.

Posted on 08-04-2018 

Comment:

To comment you must be logged in members.

Files with category

  • Android - Simple Image Capture

    Android - Simple Image Capture

    View: 580    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Image Capture using Android. This simple application can be used to any system that needed the information about the location of the user. The android is an open source operating system it's free and user friendly to...

  • Android - Simple Video Player

    Android - Simple Video Player

    View: 425    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Video Player using Android. This simple application can be use in viewing some videos. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any...

  • An Experience about Using Webview in Android Studio 3.0

    An Experience about Using Webview in Android Studio 3.0

    View: 207    Download: 0   Comment: 0

    Category: Android     Fields: Other

    I am blogging on ngocminhtran.com (using WordPress platform). Like most websites, I want to write an Android application to help viewers have a lot of great experiences with my blog.

  • Android - Simple Sending SMS

    Android - Simple Sending SMS

    View: 493    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Sending SMS using Android. This tutorial is only an example for sending an SMS, it does not contain the receiving message yet. Android is a mobile operating system developed by Google. It used in several gadget like...

  • Bomb Explode! (An Android App Strategy Game)

    Bomb Explode! (An Android App Strategy Game)

    View: 444    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This android app named Bomb Explode! is a capstone project that I made for a particular school. BOMB EXPLODE! is a Human Versus Computer strategy game. The objective is to eliminate the opponent by blowing up their BOMBS. Each player takes a turn by...

  • GIS App for Flood-Prone and Disease Affected Areas

    GIS App for Flood-Prone and Disease Affected Areas

    View: 445    Download: 1   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    GIS App for Flood-Prone and Disease Affected Areas is one of the capstone project that I have created in a particular school. Features of the application: - Geographic Map - GIS - Flood Prone Map - Urban Map - Search a particular area - Has SQLite...

  • NSO Demographic Application

    NSO Demographic Application

    View: 482    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This app is entitled NSO Demographic Application that was one of the capstone project/thesis project that I made for a particular school. This app features to provide a demographic survey of the National Statistics Office that will send to the...

  • HandEBook: An IT Portable Book Application

    HandEBook: An IT Portable Book Application

    View: 454    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This is an android mobile application entitled HandEBook: An IT Portable Book Application was one one of the capstone project that I have made in our clients at Cotabato. We used the Basic4Android software for the frontend and SQLite for the database...

 
File suggestion for you
File suggestion for you
File suggestion for you
File suggestion for you
Loading...
Loading...
Loading...
Loading...
File top downloads
File top downloads
File top downloads
File top downloads
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd