0% found this document useful (0 votes)
18 views13 pages

D.Y. Patil Technical Campus, Talsande Faculty of Engineering & Faculty of Management (Polytechnic)

Uploaded by

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

D.Y. Patil Technical Campus, Talsande Faculty of Engineering & Faculty of Management (Polytechnic)

Uploaded by

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

D.Y.

PATIL TECHNICAL CAMPUS, TALSANDE


FACULTY OF ENGINEERING & FACULTY OF
MANAGEMENT
(Polytechnic)

A Micro project Report On


“Geolocation in Android”

Submitted By

Enrollment No. Name

2112200051 Kulkarni Sanskar Mandar

Guided By
Miss. Patil S. D.

D.Y. PATIL TECHNICAL CAMPUS, TALSANDE FACULTY OF


ENGINEERING & FACULTY OF MANAGEMENT
(Polytechnic)

DEPARTMENT OF COMPUTER ENGINEERING


SEMESTER VI
CERTIFICATE

This is Certify that student of Computer Engineering has


successfully completed the project term work “Geolocation in Android” in
partial fulfilment of the Diploma of Engineering in Computer as laid down
during academic year 2023-24.

Roll No. Name of Student Exam Seat No.


3216 Kulkarni Sanskar mandar

Miss. Patil S. D. Mr. Kumbhar R. S.


Project Guide HoD

Dr. S.R. Pawaskar


Principal

Date – / /2024
Place – Talsande
INDEX

Sr No. Title Page no.

1 Introduction 1

2 Project Specification 2

3 Source Code 3-7

4 Outputs 8

5 Conclusion 9

6 References 10
Geolocation in Android

Information
Geolocation is the ability to track a device’s whereabouts using GPS, cell phone towers,
WIFI access points or a combination of these. Since devices are used by
individuals, geolocation uses positioning systems to track an individual’s whereabouts
down to latitude and longitude coordinates, or more practically, a physical address. Both
mobile and desktop devices can use geolocation.

Geolocation refers to the use of location technologies such as GPS or IP addresses to


identify and track the whereabouts of connected electronic devices.
Because these devices are often carried on an individual's person, geolocation is often used
to track the movements and location of people and surveillance.
Geolocation is used extensively in the financial services industry to help prevent fraud and
give customers information about nearby services, but may also pose unwanted privacy
issues.

D.Y. Patil Technical Campus, Talsande


Faculty of Engineering and Faculty of Management. 1 | 10
Geolocation in Android

Project Specification

• Project Details:

Geolocation in Android
01 Project Title

Useful to help prevent fraud and give


02 Purpose customers information about nearby
services
03 Front End Languages XML

03 Back End Languages JAVA

04 IDE Android Studio 2023

05 Documentation Tools Microsoft Word 2016

06 Operating System Platform Independent

D.Y. Patil Technical Campus, Talsande


Faculty of Engineering and Faculty of Management. 2 | 10
Geolocation in Android

Source Code:

activity_main.xml

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4caf50"
android:gravity="center"
android:orientation="vertical">

<TextView
android:text="START RECEIVING LOCATION OBJECT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-black"
android:text="Latitude:" />

<TextView
android:id="@+id/latTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latitude will be here! "
android:textColor="#f5f5f5" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-black"
android:text="Longitude:" />

<TextView
android:text="STOP RECEIVING LOCATION OBJECT"
android:id="@+id/lonTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude will be here! "
android:textColor="#f5f5f5" />

</LinearLayout>

D.Y. Patil Technical Campus, Talsande


Faculty of Engineering and Faculty of Management. 3 | 10
Geolocation in Android

Main_activity.java

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Looper;
import android.provider.Settings;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;

public class MainActivity extends AppCompatActivity {

// initializing
// FusedLocationProviderClient
// object
FusedLocationProviderClient mFusedLocationClient;

// Initializing other items


// from layout file
TextView latitudeTextView, longitTextView;
int PERMISSION_ID = 44;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

latitudeTextView = findViewById(R.id.latTextView);
longitTextView = findViewById(R.id.lonTextView);

mFusedLocationClient
= LocationServices.getFusedLocationProviderClient(this);
D.Y. Patil Technical Campus, Talsande
Faculty of Engineering and Faculty of Management. 4 | 10
Geolocation in Android

// method to get the location


getLastLocation();
}

@SuppressLint("MissingPermission")
private void getLastLocation() {
// check if permissions are given
if (checkPermissions()) {

// check if location is enabled


if (isLocationEnabled()) {

// getting last
// location from
// FusedLocationClient
// object

mFusedLocationClient.getLastLocation().addOnCompleteListener(new
OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull
Task<Location> task) {
Location location = task.getResult();
if (location == null) {
requestNewLocationData();
} else {

latitudeTextView.setText(location.getLatitude() + "");

longitTextView.setText(location.getLongitude() + "");
}
}
});
} else {
Toast.makeText(this, "Please turn on" + " your
location...", Toast.LENGTH_LONG).show();
Intent intent = new
Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
} else {
// if permissions aren't available,
// request for permissions
requestPermissions();
}
}

D.Y. Patil Technical Campus, Talsande


Faculty of Engineering and Faculty of Management. 5 | 10
Geolocation in Android

@SuppressLint("MissingPermission")

private void requestNewLocationData() {

// Initializing LocationRequest
// object with appropriate methods
LocationRequest mLocationRequest = new LocationRequest();

mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURA
CY);
mLocationRequest.setInterval(5);
mLocationRequest.setFastestInterval(0);
mLocationRequest.setNumUpdates(1);

// setting LocationRequest
// on FusedLocationClient
mFusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);
mFusedLocationClient.requestLocationUpdates(mLocationRequest,
mLocationCallback, Looper.myLooper());
}

private LocationCallback mLocationCallback = new LocationCallback() {

@Override
public void onLocationResult(LocationResult locationResult) {
Location mLastLocation = locationResult.getLastLocation();
latitudeTextView.setText("Latitude: " +
mLastLocation.getLatitude() + "");
longitTextView.setText("Longitude: " +
mLastLocation.getLongitude() + "");
}
};

// method to check for permissions


private boolean checkPermissions() {
return ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) ==
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) ==
PackageManager.PERMISSION_GRANTED;

// If we want background location


// on Android 10.0 and higher,
// use:

ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_BACKGROUND_LOCATION)
D.Y. Patil Technical Campus, Talsande
Faculty of Engineering and Faculty of Management. 6 | 10
Geolocation in Android

== PackageManager.PERMISSION_GRANTED
}

// method to request for permissions


private void requestPermissions() {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION},
PERMISSION_ID);
}

// method to check
// if location is enabled
private boolean isLocationEnabled() {
LocationManager locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
return
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}

// If everything is alright then


@Override
public void
onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);

if (requestCode == PERMISSION_ID) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
getLastLocation();
}
}
}

@Override
public void onResume() {
super.onResume();
if (checkPermissions()) {
getLastLocation();
}
}
}

D.Y. Patil Technical Campus, Talsande


Faculty of Engineering and Faculty of Management. 7 | 10
Geolocation in Android

Output:

D.Y. Patil Technical Campus, Talsande


Faculty of Engineering and Faculty of Management. 8 | 10
Geolocation in Android

Conclusion:

Geolocation data is something the courts have been trying to wrap their arms around for a
few years now, with no clear boundary lines yet emerging. In January 2012, the United
States Supreme Court decided in which it unanimously ruled that the attachment of a GPS
tracking device to an individual’s vehicle by police, and subsequent use of that device to
monitor the vehicle’s movements on public streets, constituted a “search or seizure” within
the meaning of the Fourth Amendment.
Contrary to many news reports at the time of the decision, however, the Jones Court
reached no conclusion on whether that search was unreasonable, or whether it required a
warrant.

D.Y. Patil Technical Campus, Talsande


Faculty of Engineering and Faculty of Management. 9 | 10
Geolocation in Android

Reference:

• https://www.sciencedirect.com/topics/computer-science/geolocation-data

• https://chat.openai.com/

• https://www.indicative.com/resource/geolocation/

• https://www.geoapify.com/what-is-geolocation

• https://developers.google.com/maps/documentation/javascript/geolocation

D.Y. Patil Technical Campus, Talsande


Faculty of Engineering and Faculty of Management. 10 |
10

You might also like