You are on page 1of 2

MAD Experiment 32

Aim: Deploy map-based application. Part II

IX. Practical related questions:

1. Explain the ways to add Markers on the Google Map.

Ans : Marker can be added by addMarker() method in onMapReady() method as :

public void onMapReady(GoogleMap googleMap)


{
mMap = googleMap;
LatLng loc = new LatLng(19.2183, 72.9781);
mMap.addMarker(new MarkerOptions().position(loc).title("Marker in Thane"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(loc));
}
2. Write the syntax for method which is used to add compass in Google Map.

Ans : Syntax to add compass in Google Map is setComapssEnabled(true);

X. Exercise :

1. Write a program to draw a route between two locations.

activity_main.xml

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


<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btnMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Map" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.xml
package com.example.expt32;
import…
public class MainActivity extends AppCompatActivity {
Button btnMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnMap=findViewById(R.id.btnMap);
btnMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri intentUri= Uri.parse("google.navigation:q=Bedekar+College,
+Thane&mode=l");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, intentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
});
}
}

AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>

You might also like