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

IWP Assignment No. 4

This document contains code for an Android application that displays a map using the Google Maps API. The AndroidManifest.xml file contains configuration details like the API key. The MapsActivity class implements the OnMapReadyCallback interface to add a marker for a location in India and move the camera to that marker when the map is ready.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views4 pages

IWP Assignment No. 4

This document contains code for an Android application that displays a map using the Google Maps API. The AndroidManifest.xml file contains configuration details like the API key. The MapsActivity class implements the OnMapReadyCallback interface to add a marker for a location in India and move the camera to that marker when the map is ready.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment No.

4
Title:Sensors for building smart applications. Use any sensors on the device to
add rich location and motion capabilities to your app from GPS or network
location to accelerometer, gyroscope, temperature, barometer and more

Name: Shrutika Dilip Khaatale

Roll No.: 25

Program:
AndroidManifest.xml

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.assignmentno4">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/Theme.AssignmentNo4">

<!--

TODO: Before you run your application, you need a Google Maps API key.

To get one, follow the directions here:

https://developers.google.com/maps/documentation/android-sdk/get-api-key

Once you have your API key (it starts with "AIza"), define a new property in your

project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the

"YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".

-->

<meta-data
android:name="com.google.android.geo.API_KEY"

android:value="AIzaSyCZMGkOgjAjaVrLfykdWg2Lp2HEqHyNv98" />

<activity

android:name=".MapsActivity"

android:exported="true"

android:label="@string/title_activity_maps">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

MapsActivity.java

package com.example.assignmentno4;

import androidx.fragment.app.FragmentActivity;

import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;

import com.google.android.gms.maps.GoogleMap;

import com.google.android.gms.maps.OnMapReadyCallback;

import com.google.android.gms.maps.SupportMapFragment;

import com.google.android.gms.maps.model.LatLng;

import com.google.android.gms.maps.model.MarkerOptions;

import com.example.assignmentno4.databinding.ActivityMapsBinding;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

private ActivityMapsBinding binding;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

binding = ActivityMapsBinding.inflate(getLayoutInflater());

setContentView(binding.getRoot());

// Obtain the SupportMapFragment and get notified when the map is ready to be used.

SupportMapFragment mapFragment = (SupportMapFragment)


getSupportFragmentManager()

.findFragmentById(R.id.map);

mapFragment.getMapAsync(this);

/**

* 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 kkw = new LatLng(20.013742600541473, 73.8222184818565);

mMap.addMarker(new MarkerOptions().position(kkw).title("Marker KKW"));


mMap.moveCamera(CameraUpdateFactory.newLatLng(kkw));

You might also like