0% found this document useful (0 votes)
18 views2 pages

pr31 (MAD)

The document contains a practical assignment for deploying a map-based application using XML and Java code. It includes the XML layout for a map fragment and Java code for an Android activity that retrieves and displays the user's location on the map. The code utilizes Google Maps API and location services to show the user's current position with a marker.
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)
18 views2 pages

pr31 (MAD)

The document contains a practical assignment for deploying a map-based application using XML and Java code. It includes the XML layout for a map fragment and Java code for an Android activity that retrieves and displays the user's location on the map. The code utilizes Google Maps API and location services to show the user's current position with a marker.
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
You are on page 1/ 2

Name: Shreyas Liladhar Lokhande Roll No: 41

Class: TYCM Batch: B

Subject: MAD
Practical No & Name: 31. Deploy map-based application. Part I

XML Code: Output:

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


<RelativeLayout
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"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mapFragment"
android:name="com.google.android.gms.maps
.SupportMapFragment"
/>
</RelativeLayout>

Java Code :
package com.example.pr31;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;

public class MainActivity extends AppCompatActivity implements


OnMapReadyCallback {
private GoogleMap mMap;
private FusedLocationProviderClient fusedLocationClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.mapFragment);
if (mapFragment != null) mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap=googleMap;
showLocation();
}
@SuppressLint("MissingPermission")
private void showLocation() {
fusedLocationClient.getLastLocation().addOnSuccessListener(this,
location -> {
if (location != null && mMap != null) {
LatLng userLocation = new LatLng(location.getLatitude(),
location.getLongitude());
mMap.addMarker(new
MarkerOptions().position(userLocation).title("You are here"));

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation,
15));
}
});
}
}

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