Practical No. 32: Aim: Deploy Map-Based Application. Part II
Practical No. 32: Aim: Deploy Map-Based Application. Part II
Practical No. 32: Aim: Deploy Map-Based Application. Part II
32
Aim: Deploy map-based application. Part II
X. Exercise
1. Write a program to draw a route between two locations.
activity_main.xml android:layout_marginTop="30dp"
<?xml version="1.0" encoding="utf-8"?> android:text="Performed by 31- Pranav
<LinearLayout Mhatre">
</TextView>
xmlns:android="http://schemas.android.com/apk/res/ </LinearLayout>
android"
xmlns:app="http://schemas.android.com/apk/res-
auto" MainActivity.java
xmlns:tools="http://schemas.android.com/tools" package com.example.exp32;
android:layout_width="match_parent"
android:layout_height="match_parent" import
android:orientation="vertical" androidx.appcompat.app.AppCompatActivity;
android:padding="16dp"
android:gravity="center_horizontal" import
tools:context=".MainActivity"> android.content.ActivityNotFoundException;
<EditText import android.content.Intent;
android:layout_width="match_parent" import android.net.Uri;
android:layout_height="wrap_content" import android.os.Bundle;
android:id="@+id/et_source" import android.view.Display;
android:hint="Enter Source Location" import android.view.View;
android:padding="12dp" import android.widget.Button;
android:layout_marginTop="100dp" import android.widget.EditText;
import android.widget.Toast;
android:background="@android:drawable/editbox_b
ackground"/> public class MainActivity extends
<EditText AppCompatActivity {
android:layout_width="match_parent"
android:layout_height="wrap_content" EditText etSource,etDestination;
android:id="@+id/et_destination" Button btTrack;
android:hint="Enter Destination Location"
android:padding="12dp" @Override
android:layout_marginTop="8dp" protected void onCreate(Bundle
savedInstanceState) {
android:background="@android:drawable/editbox_b super.onCreate(savedInstanceState);
ackground"/> setContentView(R.layout.activity_main);
<Button
android:layout_width="wrap_content" etSource =
android:layout_height="wrap_content" findViewById(R.id.et_source);
android:id="@+id/bt_track" etDestination =
android:text="Display Route" findViewById(R.id.et_destination);
android:layout_marginTop="16dp"/> btTrack = findViewById(R.id.bt_track);
<TextView
android:layout_width="wrap_content" btTrack.setOnClickListener(new
android:layout_height="wrap_content" View.OnClickListener() {
android:textStyle="bold" @Override
android:textSize="20sp" public void onClick(View v) {
String sSource = Output:
etSource.getText().toString().trim();
String sDestination =
etDestination.getText().toString().trim();
if(sSource.equals("") &&
sDestination.equals("")){
Toast.makeText(MainActivity.this,
"Enter both locations",
Toast.LENGTH_SHORT).show();
}else{
DisplayTrack(sSource,sDestination);
}
}
});
intent.setPackage("com.google.android.apps.maps");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TA
SK);
startActivity(intent);
}catch (ActivityNotFoundException e){
Uri uri =
Uri.parse("https://play.google.com/store/apps/details
?id=com.google.android.apps.maps");
Intent intent= new
Intent(Intent.ACTION_VIEW,uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TA
SK);
startActivity(intent);
}
}
}