0% found this document useful (0 votes)
14 views4 pages

Draw Route Between Locations in Android

The document provides a code example for an Android application that uses Google Maps to draw a route between two locations, Kolhapur and Mumbai. It includes the layout in XML and the main activity in Java, detailing the setup of the MapView, markers, and polyline for the route. Additionally, it outlines necessary permissions and metadata for the AndroidManifest.xml file to enable location access and API key integration.

Uploaded by

ganeshkumbhar638
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)
14 views4 pages

Draw Route Between Locations in Android

The document provides a code example for an Android application that uses Google Maps to draw a route between two locations, Kolhapur and Mumbai. It includes the layout in XML and the main activity in Java, detailing the setup of the MapView, markers, and polyline for the route. Additionally, it outlines necessary permissions and metadata for the AndroidManifest.xml file to enable location access and API key integration.

Uploaded by

ganeshkumbhar638
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

Q.

Write a program to draw a route between import


two locations [Link]
Options;
activity_main.xml
import
<FrameLayout [Link]
eOptions;
xmlns:android="[Link] import [Link];
apk/res/android"
android:layout_width="match_parent" public class MainActivity extends
android:layout_height="match_parent"> AppCompatActivity implements
OnMapReadyCallback {
<[Link]
android:id="@+id/mapView" private MapView mapView;
android:layout_width="match_parent" private GoogleMap googleMap;
android:layout_height="match_parent" /> private static final String
MAP_VIEW_BUNDLE_KEY =
</FrameLayout> "MapViewBundleKey";

[Link] @Override
package [Link].practicalno32; protected void onCreate(Bundle
savedInstanceState) {
import [Link]; [Link](savedInstanceState);
import setContentView([Link].activity_main);
[Link]
; mapView =
import [Link]; findViewById([Link]);
import Bundle mapViewBundle = null;
[Link] if (savedInstanceState != null) {
eFactory; mapViewBundle =
import
[Link]; [Link](MAP_VIEW_
import BUNDLE_KEY);
[Link]; }
import [Link](mapViewBundle);
[Link] [Link](this);
Callback; }
import
[Link] @Override
; public void onMapReady(@NonNull
GoogleMap map) {
googleMap = map;
[Link]();
LatLng kolhapur = new LatLng(16.7050, [Link]();
74.2433); }
LatLng mumbai = new LatLng(19.0760,
72.8777); @Override
protected void onStop() {
[Link](new [Link]();
[Link]();
MarkerOptions().position(kolhapur).title("Ko }
lhapur"));
[Link](new @Override
protected void onDestroy() {
MarkerOptions().position(mumbai).title("Mu [Link]();
mbai")); [Link]();
}
[Link](CameraUpdateFact
[Link](kolhapur, @Override
6)); public void onLowMemory() {
[Link]();
[Link](new [Link]();
PolylineOptions() }
.add(kolhapur)
.add(mumbai) @Override
.width(8) protected void
.color([Link])); onSaveInstanceState(@NonNull Bundle
} outState) {
[Link](outState);
@Override
protected void onStart() { Bundle mapViewBundle =
[Link](); [Link](MAP_VIEW_BUNDLE_
[Link](); KEY);
} if (mapViewBundle == null) {
mapViewBundle = new Bundle();
@Override
protected void onResume() { [Link](MAP_VIEW_BUNDLE_
[Link](); KEY, mapViewBundle);
[Link](); }
}
[Link](mapViewBun
@Override dle);
protected void onPause() { }
} <meta-data

[Link] android:name="[Link]
_KEY"
<?xml version="1.0" encoding="utf-8"?> android:value="YOUR_API_KEY" />
<manifest <!-- Replace with your actual API key -->
xmlns:android="[Link]
apk/res/android" <activity
android:name=".MainActivity"
xmlns:tools="[Link] android:exported="true">
ls"> <intent-filter>
<action
<uses-permission android:name="[Link]"
android:name="[Link] />
_FINE_LOCATION" /> <category
<uses-permission android:name="[Link]
android:name="[Link] NCHER" />
_COARSE_LOCATION" /> </intent-filter>
<uses-permission </activity>
android:name="[Link] </application>
ET" />
</manifest>
<application
android:allowBackup="true"

android:dataExtractionRules="@xml/data_ex
traction_rules"

android:fullBackupContent="@xml/backup_
rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_
round"
android:supportsRtl="true"

android:theme="@style/Theme.PracticalNo3
2"
tools:targetApi="31">

You might also like