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

Android Map Integration Example

The document describes an Android application that displays a map and allows switching between satellite, terrain, normal and hybrid map views. It includes the XML layout and Java code for a map activity that centers the map on a location, adds markers and draws a polyline between two points.

Uploaded by

Aniket Shekokar
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)
55 views9 pages

Android Map Integration Example

The document describes an Android application that displays a map and allows switching between satellite, terrain, normal and hybrid map views. It includes the XML layout and Java code for a map activity that centers the map on a location, adds markers and draws a polyline between two points.

Uploaded by

Aniket Shekokar
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

Task 9 Part B

Name: Aniket Sarang Shekokar

• Code

1. My Location xml:===

<RelativeLayout xmlns:android="[Link]
xmlns:map="[Link]
xmlns:tools="[Link]
android:name="[Link]"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyLocationActivity">

<fragment
android:id="@+id/map"
android:name="[Link]"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_my_location_satellite"
android:text="Satellite"
android:textSize="12sp"
android:textStyle="bold"
android:fontFamily="sans-serif-condensed-medium"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_my_location_terrain"
android:text="Terrain"
android:textSize="12sp"
android:textStyle="bold"
android:fontFamily="sans-serif-condensed-medium"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_my_location_normal"
android:text="Normal"
android:textSize="12sp"
android:textStyle="bold"
android:fontFamily="sans-serif-condensed-medium"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_my_location_hybrid"
android:text="Hybrid"
android:textSize="12sp"
android:textStyle="bold"
android:fontFamily="sans-serif-condensed-medium"/>

</LinearLayout>

</RelativeLayout>

2. My Location Activity:==

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MyLocationActivity extends FragmentActivity implements


OnMapReadyCallback {

private GoogleMap mMap;


Button btn_satellite,btn_terrain,btn_normal,btn_hybrid;

private ActivityMyLocationBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);

binding = [Link](getLayoutInflater());
setContentView([Link]());

// Obtain the SupportMapFragment and get notified when the map is


ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById([Link]);
[Link](this);

btn_satellite = findViewById([Link].btn_my_location_satellite);
btn_terrain = findViewById([Link].btn_my_location_terrain);
btn_normal = findViewById([Link].btn_my_location_normal);
btn_hybrid = findViewById([Link].btn_my_location_hybrid);
}

/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the
camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will
be prompted to install
* it inside the SupportMapFragment. This method will only be triggered
once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Add a marker in Sydney and move the camera


LatLng myLocation = new LatLng(20.875439,76.205382);
[Link](new MarkerOptions().position(myLocation).title("Marker
in Harikiran sociaty malkapur"));
// [Link]([Link](myLocation));

[Link]([Link](myLocation,16),5000,null
);
[Link](new CircleOptions()
.center(myLocation)
.fillColor([Link]("#73B8EF"))
.strokeColor([Link])
.radius(150)
);

btn_satellite.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link](GoogleMap.MAP_TYPE_SATELLITE);
}
});

btn_terrain.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link](GoogleMap.MAP_TYPE_TERRAIN);
}
});

btn_normal.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link](GoogleMap.MAP_TYPE_NORMAL);
}
});

btn_hybrid.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link](GoogleMap.MAP_TYPE_HYBRID);
}
});

MarkerOptions markerOptions = new MarkerOptions();


LatLng malkapur = new LatLng(20.901262,76.198688);
[Link](malkapur);
[Link]("Marker in V B Kolte collge of engineering");
[Link](markerOptions);

[Link](new PolylineOptions()
.add(new LatLng(20.875439,76.205382),
(new LatLng(20.901262,76.198688)))
.width(5)
.color([Link])
.geodesic(true)

);

}
}

Output:==

You might also like