Giter Site home page Giter Site logo

gpstracker-2's Introduction

GPSTracker

A light weight library for getting current user location, latitude, longitude, address, ip address and many more.

Step 1) Add library to your app level build file.

- compile'com.github.ankitdubey021:GPSTracker:1.1'

Step 2) Add permission in manifest file as-

+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Step 3) create object of MyTracker class

- MyTracker tracker=new MyTracker(this);

Sample Code

private static final int REQUEST_CODE_PERMISSION = 2;
String mPermission = Manifest.permission.ACCESS_FINE_LOCATION;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try { if (ActivityCompat.checkSelfPermission(this, mPermission) != MockPackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(this, new String[]{mPermission, Manifest.permission.READ_PHONE_STATE},
                    REQUEST_CODE_PERMISSION);
        }else{
            //read location
            getLocation();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case REQUEST_CODE_PERMISSION:
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                getLocation();
            } else {
                System.out.println("permission denied!");
            }
            break;
    }
}
void getLocation(){
    MyTracker tracker=new MyTracker(this);
    System.out.println(tracker.getLatitude());
    System.out.println(tracker.getLongitude());
    System.out.println(tracker.getLocation());
    System.out.println(tracker.address);
    System.out.println(tracker.cityName);
    System.out.println(tracker.state);
    System.out.println(tracker.countryName);
    System.out.println(tracker.countryCode);
    System.out.println(tracker.ipAddress);
    System.out.println(tracker.macAddress);
}

gpstracker-2's People

Contributors

ankitdubey021 avatar

Watchers

Michael jentsch avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.