Practical No 32

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Practical No 32

AIM:- Deploy map based application. Part II

CODE:-
.xml file

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


<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com
/apk/res/android"

xmlns:app="http://schemas.android.com/apk
/res-auto"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"android:layout_height="match_parent"
android:orientation="vertical" android:padding="16dp"
android:gravity="center_horizontal" tools:context=".MainActivity">
<EditText android:id="@+id/et_source" android:layout_width="317dp"
android:layout_height="56dp" android:layout_marginTop="220dp"

android:background="@android:drawable/editbox_background"

android:hint="Enter Source Location"android:padding="12dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"
/>
<EditText android:id="@+id/et_destination"

android:layout_width="317dp" android:layout_height="52dp"
android:layout_marginTop="36dp"

android:background="@android:drawable/editbox_background"
android:hint="Enter DestinationLocation"
android:padding="12dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/et_source" />
<Button
android:id="@+id/bt_track" android:layout_width="wrap_content"
android:layout_height="wrap_content"android:layout_marginTop="56dp"
android:text="Display Location" app:backgroundTint="#3F51B5"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/et_destination" />
</androidx.constraintlayout.widget.ConstraintLayout>

.java file
package com.example.coexp32;

import android.content.ActivityNotFoundException
;
import android.content.Intent;import android.net.Uri; import
android.os.Bundle; import android.widget.Button;
import android.widget.EditText;import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extendsAppCompatActivity {
EditText etSource,etDestination;Button btTrack;
@Override
protected void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);etSource =
findViewById(R.id.et_source);etDestination =
findViewById(R.id.et_destination);btTrack =
findViewById(R.id.bt_track); btTrack.setOnClickListener(v -> {
String sSource = etSource.getText().toString().trim();
String sDestination = etDestination.getText().toString().trim();
if(sSource.equals("") &&sDestination.equals("")){
Toast.makeText(MainActivity.this,"Enter both location",
Toast.LENGTH_SHORT).show();
}else{

DisplayTrack(sSource,sDestination); }}); } private void DisplayTrack(String sSource,


String sDestination) {try{

Uri uri = Uri.parse("https://www.google.co.in/maps/dir/" + sSource + "/" +


sDestination);
Intent intent= new Intent(Intent.ACTION_VIEW,uri);

intent.setPackage("com.google.android.apps
.maps");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}catch (ActivityNotFoundException
e){
Uri uri = Uri.parse("https://play.google.com/store/app
s/details?id=com.google.android.apps.maps"
);
Intent intent= new Intent(Intent.ACTION_VIEW,uri);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}}}

OUTPUT:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy