0% found this document useful (0 votes)
4 views9 pages

MAD Lab Rep 05 - 546 - Hasibul Hassan

bhjo;jokp
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)
4 views9 pages

MAD Lab Rep 05 - 546 - Hasibul Hassan

bhjo;jokp
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/ 9

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: Summer,Year: 2025, B.Sc. in CSE (Regular)

LAB REPORT NO- 05


Course Title: Mobile Application and Development Lab
Course Code: CSE-426 Section: 221-D4

Lab Exp Name: Design Location Finder App with Nearby Restaurants and Hospitals using
Google Maps
Student Details

Name ID
Hasibul Hassan 221002546

Lab Date : 13-08-2025


Submission Date : 20-08-2025
Course Teacher’s Name : Abida Sultana

[For Teachers use only: Don’t Write Anything inside this box]

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................

1
1. TITLE OF THE LAB EXPERIMENT

1. Implement timestamp along with latitude and longitude information.


2. Show nearby restaurants and hospital from your current location.

2.OBJECTIVES:

➢ To make a simple location finder app using Android Studio


➢ To show the current time, latitude, and longitude on the screen
➢ To let users see nearby restaurants on Google Maps
➢ To let users see nearby hospitals on Google Maps
➢ To ask for location permission from the user and use it
➢ To show messages using Toast when location is not ready or permission is denied
➢ To make the app interface clean, simple, and attractive

3.PROCEDURE :

Step: 01

➢ Open Android Studio.


➢ Click on “New Project”.
➢ Choose “Empty Activity”.
➢ Give your project the name “MyLocationFinder”.
➢ Select Java as the programming language.
➢ Click “Finish” to create the project.

Step: 02

➢ Open the file named activity_main.xml.


➢ Use LinearLayout to design the screen layout.
➢ Add a TextView to show the title “ My Location Finder”.
➢ Add another LinearLayout or CardView to show location and time.
➢ Add two Buttons: one for “Show Nearby Restaurants” and one for “Show Nearby
Hospitals”.
➢ Change background color, add padding and margin, set text size, and choose button
colors to make the app look nice.

2
Step: 03

➢ Open the file MainActivity.java.


➢ Connect TextView and Buttons to the code using findViewById().
➢ Create a FusedLocationProviderClient to get the user’s current location.
➢ Request location permission from the user using ActivityCompat.
➢ Add click listeners on both Buttons to open Google Maps for restaurants and
hospitals.
➢ Get the current date and time and show it along with latitude and longitude in the
TextView.
➢ Show a small message (Toast) if location is not ready or permission is denied.

Step: 04

➢ Create a method getCurrentLocation() to get latitude and longitude.


➢ Use fusedLocationClient.getLastLocation() to get the location.
➢ Format the current time using SimpleDateFormat and show it on the screen.
➢ Save latitude and longitude in variables to use when opening Google Maps.

Step: 05

➢ Create a method openMap(String placeType) to open Google Maps.


➢ Use Intent.ACTION_VIEW with a geo URI to search for restaurants or hospitals.
➢ Set the package to “com.google.android.apps.maps” so it opens in Google Maps.
➢ Start the activity with startActivity(intent).

Step: 06

➢ Override onRequestPermissionsResult() to handle user’s location permission.


➢ If permission is granted, call getCurrentLocation() again.
➢ If permission is denied, show a Toast message saying “Permission denied”.

Step: 07

➢ Run the app on an emulator or real Android phone.


➢ Allow location permission when asked.
➢ Check if current time, latitude, and longitude appear on the screen.
➢ Press “Show Nearby Restaurants” or “Show Nearby Hospitals” to see results in
Google Maps.
3
3. IMPLEMENTATION :

➢ 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:orientation="vertical"
android:background="#F5F7FA"
android:gravity="center"
android:padding="20dp">

<!-- App Title -->


<TextView
android:id="@+id/titleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" My Location Finder"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="#2C3E50"
android:layout_marginBottom="20dp" />

<!-- Location Info Card -->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="@drawable/card_background"
android:elevation="6dp"
android:layout_marginBottom="20dp">

<TextView
android:id="@+id/locationInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"

4
android:text="Location and Time will appear here"
android:textSize="16sp"
android:textColor="#34495E" />

</LinearLayout>

<!-- Restaurants Button -->


<Button
android:id="@+id/btnRestaurants"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="🍽 Show Nearby Restaurants"
android:backgroundTint="#27AE60"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:layout_marginBottom="12dp" />

<!-- Hospitals Button -->


<Button
android:id="@+id/btnHospitals"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Show Nearby Hospitals"
android:backgroundTint="#2980B9"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:layout_marginBottom="20dp" />

</LinearLayout>

5
➢ MainActivity.java :

package com.example.locationapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.core.app.ActivityCompat;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

TextView locationInfo;
Button btnRestaurants, btnHospitals;
FusedLocationProviderClient fusedLocationClient;
double currentLat = 0.0, currentLng = 0.0;

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

locationInfo = findViewById(R.id.locationInfo);
btnRestaurants = findViewById(R.id.btnRestaurants);
btnHospitals = findViewById(R.id.btnHospitals);

fusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);

getCurrentLocation();

btnRestaurants.setOnClickListener(v -> {
if (currentLat != 0 && currentLng != 0) {
openMap("restaurant");
} else {

6
Toast.makeText(this, "Location not ready yet",
Toast.LENGTH_SHORT).show();
}
});

btnHospitals.setOnClickListener(v -> {
if (currentLat != 0 && currentLng != 0) {
openMap("hospital");
} else {
Toast.makeText(this, "Location not ready yet",
Toast.LENGTH_SHORT).show();
}
});
}

private void getCurrentLocation() {


if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
return;
}

fusedLocationClient.getLastLocation().addOnSuccessListener(location -> {
if (location != null) {
currentLat = location.getLatitude();
currentLng = location.getLongitude();

String timeStamp = new SimpleDateFormat("yyyy-MM-dd


HH:mm:ss", Locale.getDefault())
.format(new Date());

locationInfo.setText("Time: " + timeStamp +


"\nLatitude: " + currentLat +
"\nLongitude: " + currentLng);
} else {
Toast.makeText(this, "Unable to get location",
Toast.LENGTH_SHORT).show();
}
});
}

private void openMap(String placeType) {


String uri = "geo:" + currentLat + "," + currentLng + "?q=" +
7
placeType;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull
String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
if (requestCode == 1 && grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getCurrentLocation();
} else {
Toast.makeText(this, "Permission denied",
Toast.LENGTH_SHORT).show();
}
}
}

4. OUTPUT:

8
5. ANALYSIS AND DISCUSSION:

In this project, I made a simple location finder app. It shows the current time, latitude, and
longitude. Users can find nearby restaurants and hospitals using Google Maps. I learned how to
get location from the device, ask for permissions, use buttons to open Maps, show messages with
Toast, and design a simple and attractive interface.

You might also like