0% found this document useful (0 votes)
4 views

Messaging in Android

The document provides an overview of SMS messaging in Android, detailing the built-in messaging app, SMS APIs, permissions required for sending and reading messages, and the ability to set a default SMS app. It includes code examples for sending SMS programmatically using the SmsManager class and through implicit intents, as well as necessary permissions to declare in the AndroidManifest.xml file. Additionally, it touches on integrating Google Maps into Android apps, highlighting types of maps and methods available for developers.

Uploaded by

INDHU MATHI
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)
4 views

Messaging in Android

The document provides an overview of SMS messaging in Android, detailing the built-in messaging app, SMS APIs, permissions required for sending and reading messages, and the ability to set a default SMS app. It includes code examples for sending SMS programmatically using the SmsManager class and through implicit intents, as well as necessary permissions to declare in the AndroidManifest.xml file. Additionally, it touches on integrating Google Maps into Android apps, highlighting types of maps and methods available for developers.

Uploaded by

INDHU MATHI
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/ 22

SMS messaging In Android

In Android, SMS messaging is a core feature of the operating system, allowing users to send and
receive text messages using the built-in messaging app or third-party messaging apps available on
the Google Play Store. Here's a brief overview of SMS messaging on Android:

1. Messaging App: Android devices typically come pre-installed with a messaging app that
allows users to compose, send, and receive SMS messages. This app may vary slightly depending on
the manufacturer or version of Android, but it generally provides basic messaging functionality such
as text input, message threading, and contact management.

2. SMS APIs: Android provides developers with APIs (Application Programming Interfaces) for
interacting with SMS messaging functionality within their apps. Developers can use these APIs to
send SMS messages programmatically from their apps, monitor incoming messages, and perform
other tasks related to SMS communication.

3. Permissions: To access SMS messaging features on Android, apps typically require the
appropriate permissions. For example, an app that sends SMS messages on behalf of the user would
need the SEND_SMS permission, while an app that reads incoming SMS messages would need the
READ_SMS permission.

4. Default SMS App: Android allows users to set a default SMS app, which is the app that
handles all SMS-related tasks by default. When a user receives an SMS message, it's the default SMS
app that processes and displays the message. Users can change their default SMS app in the system
settings.

5. Integration with Other Services: Android apps can integrate SMS messaging functionality
with other services and features of the device. For example, an app might use SMS for two-factor
authentication, verification codes, or notifications.

6. Enhanced Messaging Features: Some Android devices and messaging apps support
enhanced messaging features such as RCS (Rich Communication Services). RCS builds upon the
traditional SMS protocol to offer features similar to those found in internet-based messaging apps,
such as group chats, high-resolution images, read receipts, and typing indicators.

Sending sms message programmatically


To send SMS messages programmatically in an Android app, you can use the
SmsManager class provided by the Android SDK. Here's a basic example of how you can
send an SMS message:

JAVA CODE :

import android.telephony.SmsManager;

import android.app.PendingIntent;

import android.content.Intent;
import android.content.Context;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Your message content and destination phone number

String message = "Hello, this is a test message!";

String phoneNumber = "1234567890";

// Check if app has permission to send SMS

if (checkSelfPermission(Manifest.permission.SEND_SMS) ==
PackageManager.PERMISSION_GRANTED) {

// If permission is granted, send the SMS

sendSMS(phoneNumber, message);

} else {

// If permission is not granted, request it from the user

requestPermissions(new String[]{Manifest.permission.SEND_SMS}, 1);

// Method to send SMS message

private void sendSMS(String phoneNumber, String message) {

// Get the default instance of SmsManager

SmsManager smsManager = SmsManager.getDefault();


// Create a PendingIntent to track the sent SMS

PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0, new


Intent("SMS_SENT"), 0);

// Send the SMS message

smsManager.sendTextMessage(phoneNumber, null, message, sentIntent, null);

// Handle permission request result

@Override

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[]


grantResults) {

super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == 1) {

if (grantResults.length > 0 && grantResults[0] ==


PackageManager.PERMISSION_GRANTED) {

// If permission is granted, send the SMS

sendSMS(phoneNumber, message);

} else {

// If permission is denied, inform the user

Toast.makeText(this, "SMS permission denied", Toast.LENGTH_SHORT).show();

Make sure to add the necessary permissions to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.SEND_SMS" />

In this example, the sendSMS() method sends an SMS message with the specified content
(message) to the specified phone number (phoneNumber). Before sending the SMS, the app
checks if it has the necessary permission to send SMS messages. If permission is granted, the
SMS is sent; otherwise, the app requests permission from the user.

This is a basic example to get you started. Depending on your requirements, you may need
to handle additional scenarios, such as handling delivery reports, checking for network
connectivity, and handling errors.

SMS message using an implicit intent in Android


you can also send an SMS message using an implicit intent in Android. Here's how you can
do it:

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Your message content and destination phone number

String message = "Hello, this is a test message!";

String phoneNumber = "1234567890";

// Create an intent with action ACTION_SENDTO

Intent intent = new Intent(Intent.ACTION_SENDTO);

// Set the data (URI) for the intent


Uri uri = Uri.parse("smsto:" + phoneNumber); // "smsto:" for sending SMS

intent.setData(uri);

// Set the message content

intent.putExtra("sms_body", message);

// Check if there's an activity that can handle the intent

if (intent.resolveActivity(getPackageManager()) != null) {

// Start the activity (SMS app) to send the message

startActivity(intent);

} else {

// Handle case where no SMS app is available

// You may inform the user to install a messaging app

// or provide an alternative method for sending messages

SMS MANAGER

The SmsManager class in Android provides methods for sending SMS messages
programmatically without the need for user interaction. Here's how you can use
SmsManager to send an SMS message:

import android.Manifest;

import android.app.PendingIntent;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.os.Bundle;

import android.telephony.SmsManager;

import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

import androidx.core.app.ActivityCompat;

import androidx.core.content.ContextCompat;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Request permission to send SMS if not already granted

if (ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS) !=
PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this, new String[]


{Manifest.permission.SEND_SMS}, 1);

} else {

// If permission is already granted, send SMS

sendSMS("1234567890", "Hello, this is a test message!");

@Override

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[]


grantResults) {

super.onRequestPermissionsResult(requestCode, permissions, grantResults);


if (requestCode == 1 && grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {

// If permission is granted, send SMS

sendSMS("1234567890", "Hello, this is a test message!");

} else {

Toast.makeText(this, "SMS permission denied", Toast.LENGTH_SHORT).show();

private void sendSMS(String phoneNumber, String message) {

// Create PendingIntent to track the sent SMS

PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0, new


Intent("SMS_SENT"), 0);

// Get the default instance of SmsManager

SmsManager smsManager = SmsManager.getDefault();

// Split message into parts if message length exceeds SMS character limit

// (In a real application, you might want to handle this more robustly)

if (message.length() > SmsManager.MAX_TEXT_LENGTH) {

// Split the message into multiple parts

// This may result in multiple messages being sent if the message is long

for (String part : smsManager.divideMessage(message)) {

smsManager.sendTextMessage(phoneNumber, null, part, sentIntent, null);

} else {

// Message fits within SMS character limit, send as is


smsManager.sendTextMessage(phoneNumber, null, message, sentIntent, null);

In this code:

We first check if the app has permission to send SMS messages using checkSelfPermission. If
not, we request permission from the user using requestPermissions.

When permission is granted (either initially or after the user grants it), we call the sendSMS
method to actually send the message.

In the sendSMS method, we create a PendingIntent to track the sent SMS.

We obtain an instance of SmsManager using getDefault.

If the length of the message exceeds the maximum length allowed for a single SMS (160
characters), we split the message into multiple parts and send each part separately.
Otherwise, we send the message as is.

Remember to add the necessary permissions to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.SEND_SMS" />

This code sends a simple SMS message without handling delivery reports or errors. In a real
application, you might want to handle these scenarios more gracefully.

Key Methods and Functionality:

getDefault():

This static method returns the default instance of SmsManager.


Example: SmsManager smsManager = SmsManager.getDefault();

sendTextMessage():

This method sends a simple text SMS message to the specified destination address.

Parameters:

destinationAddress: The phone number of the recipient.

scAddress: Service center address (null for default).

text: The message content.

sentIntent: A PendingIntent to be broadcast when the message is sent.

deliveryIntent: A PendingIntent to be broadcast when the message is delivered (optional).

Example: smsManager.sendTextMessage("1234567890", null, "Hello", sentIntent, null);

divideMessage():

This method splits a long message into multiple parts, each within the character limit of an
SMS.

Returns an ArrayList<String> containing the message parts.

Example: ArrayList<String> messageParts = smsManager.divideMessage(longMessage);

sendMultipartTextMessage():

This method sends a multipart SMS message when the message length exceeds the
character limit of a single SMS.

Parameters:

destinationAddress: The phone number of the recipient.

scAddress: Service center address (null for default).

parts: An ArrayList<String> containing the message parts.

sentIntents: An array of PendingIntents to be broadcast when each message part is sent.

deliveryIntents: An array of PendingIntents to be broadcast when each message part is


delivered (optional).
Example:

smsManager.sendMultipartTextMessage("1234567890", null, messageParts, sentIntents,


null);

Permissions:

To use SmsManager in your Android application, you need to declare the SEND_SMS
permission in your AndroidManifest.xml file:

<uses-permission android:name="android.permission.SEND_SMS" />

DISPLAYING MAPS
Google Maps is a powerful mapping service provided by Google that offers a wide range of
features for Android developers to integrate into their applications. Here's an overview of
how you can integrate Google Maps into your Android app:

1. Obtain an API Key:

To use Google Maps in your Android app, you need to obtain an API key from the Google
Cloud Console. This key authenticates your app with the Google Maps service. Follow the
official documentation to obtain an API key: Get API Key

2. Add Google Play Services dependency:

Add the Google Play Services dependency to your app's build.gradle file:

implementation 'com.google.android.gms:play-services-maps:20.0.0'

3. Configure Google Maps in your layout XML:

Add a MapView element to your layout XML file where you want to display the map:

<com.google.android.gms.maps.MapView

android:id="@+id/map_view"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

4. Initialize Google Maps in your Activity:

In your Activity or Fragment, initialize the Google Maps instance using the API key obtained
earlier:

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

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

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

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {

private MapView mapView;

private GoogleMap googleMap;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_maps);

mapView = findViewById(R.id.map_view);

mapView.onCreate(savedInstanceState);

mapView.getMapAsync(this);

@Override

public void onMapReady(GoogleMap map) {

googleMap = map;

// You can customize the map here

@Override
public void onResume() {

super.onResume();

mapView.onResume();

@Override

public void onPause() {

super.onPause();

mapView.onPause();

@Override

public void onDestroy() {

super.onDestroy();

mapView.onDestroy();

@Override

public void onLowMemory() {

super.onLowMemory();

mapView.onLowMemory();

5. Customize and Interact with the Map:

Once you have the Google Map instance, you can customize it and add various features such
as markers, polygons, polylines, and more. You can also handle user interactions like tapping
on markers or dragging the map.
6. Permissions:

Ensure that your app has the necessary permissions declared in the AndroidManifest.xml
file, such as ACCESS_FINE_LOCATION for accessing the user's location.

7. Additional Features:

Explore additional features provided by the Google Maps SDK, such as Street View,
Geocoding, Places API, Directions API, and more.

TYPES OF GOOGLE MAPS


In Android mobile application development, there are primarily three types of Google Maps
implementations:

1. Basic Map Display:

This type involves displaying a basic map in your application, usually with default map tiles
provided by Google. Users can interact with the map by panning, zooming, and tapping on
it.

Use cases: Displaying points of interest, landmarks, or general geographical information


within your app.

2. Map with Markers:

In addition to displaying the map, this type involves adding markers to specific locations on
the map. Markers can represent points of interest, locations of interest, or custom data
points.

Use cases: Showing the location of nearby businesses, events, or attractions. Also commonly
used for navigation apps to display waypoints or destinations.

3. Map with Advanced Features:

This type extends beyond basic map display and marker placement to include more
advanced features such as:

 Custom markers: Use custom icons or graphics for markers.


 Info windows: Display additional information when a user taps on a marker.
 Polylines and polygons: Draw lines or shapes on the map to represent routes,
boundaries, or areas of interest.
 User location: Display the user's current location on the map, with or without
continuous updates.
 Geocoding and reverse geocoding: Convert between geographic coordinates and
human-readable addresses, and vice versa.
 Street View: Embed Street View imagery in your app to provide a 360-degree
panoramic view of locations.
 Places API: Integrate Google Places API to search for places, get place details, and
display place autocomplete suggestions.
 Directions API: Request directions between two or more locations, with options for
different travel modes (driving, walking, transit, etc.).
 Use cases: Building navigation apps, location-based services, delivery or
transportation apps, re al-time tracking, and more.

METHODS OF GOOGLE MAPS

In Android development, Google Maps functionality is primarily accessed and utilized


through methods provided by the Google Maps Android API. These methods allow
developers to interact with maps, add markers, draw shapes, obtain user location, and
more. Here are some common methods used in Google Maps Android API:

1. getMapAsync(OnMapReadyCallback callback):

This method is used to asynchronously initialize the map and set up its properties.

It takes an OnMapReadyCallback as a parameter, which is invoked when the map is


ready to be used.

mapView.getMapAsync(new OnMapReadyCallback() {

@Override

public void onMapReady(GoogleMap googleMap) {

// Map setup code

});

2. addMarker(MarkerOptions options):

This method adds a marker to the map at a specified location with the given options.
It returns a Marker object representing the added marker, which can be used to
manipulate the marker later.

Example:
MarkerOptions markerOptions = new MarkerOptions()

.position(new LatLng(latitude, longitude))

.title("Marker Title")

.snippet("Marker Snippet");

Marker marker = googleMap.addMarker(markerOptions);

3. moveCamera(CameraUpdate update):
This method moves the camera position to the specified location or zoom level on
the map.
It takes a CameraUpdate object as a parameter, which can be created using various
factory methods like newLatLng() or newLatLngZoom().

Example:

CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new


LatLng(latitude, longitude), 15);

googleMap.moveCamera(cameraUpdate);

4. setOnMarkerClickListener(GoogleMap.OnMarkerClickListener listener):

This method sets a listener to be notified when a marker on the map is clicked.

It takes a GoogleMap.OnMarkerClickListener object as a parameter, with a callback


method onMarkerClick() to handle marker click events.

Example:

googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

@Override

public boolean onMarkerClick(Marker marker) {

// Handle marker click

return true; // Return true to consume the event

});

5. setMyLocationEnabled(boolean enabled):
This method enables or disables the "My Location" layer on the map, which shows
the user's current location.

It requires the appropriate permissions and runtime permission checks for accessing
the device's location.

Example:

if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) ==
PackageManager.PERMISSION_GRANTED) {

googleMap.setMyLocationEnabled(true);

These are just a few examples of the many methods provided by the Google
Maps Android API. Depending on your application's requirements, you can use these
methods and more to create rich and interactive map experiences for your users.

STEPS FOR GETTING THE GOOGLE MAPS API KEY


The steps for obtaining a Google Maps API key for mobile application development:

1. Create a Google Cloud Platform (GCP) Account: If you don't have one already, sign up
for a Google Cloud Platform account.

2. Enable the Maps SDK for Android or iOS: Go to the Google Cloud Platform Console
and enable the Maps SDK for Android or iOS, depending on the platform you're
developing for.

3. Create a New Project: Create a new project in the Google Cloud Platform Console for
your mobile application.

4. Create an API Key: Navigate to the "APIs & Services" > "Credentials" page in the
Google Cloud Platform Console. Click on "Create credentials" and select "API key".

5. Restrict the API Key (Optional but Recommended): To enhance security, restrict your
API key by specifying which APIs it can access and from which applications. You can
set restrictions based on Android apps, iOS apps, or HTTP referrers.
6. Add the API Key to your Mobile Application: Once you have your API key, integrate it
into your mobile application code by adding it to the appropriate configuration file
(like AndroidManifest.xml for Android or Info.plist for iOS).

7. Test your Application: Test your application to ensure that the Google Maps
functionality is working correctly.

8. Monitor Usage and Billing: Keep an eye on your usage through the Google Cloud
Platform Console to ensure that you stay within any free usage limits and to monitor
any associated charges.

CALLBACKS IN GOOGLE MAPS


Callbacks in Google Maps API are functions that you can define to be executed when certain
events occur within the map. These callbacks allow you to customize the behavior of your
map application and respond to user interactions or changes in the map state. Here are
some common callbacks available in Google Maps API:

1. Event Listeners: Event listeners are used to listen for various user interactions with
the map, such as clicks, mouse movements, or changes in the map's viewport. For
example, you can use addListener() to listen for a click event on a map marker and
execute a function when the marker is clicked.
2. Map Events: Google Maps API provides several map events that you can listen to,
such as bounds_changed, center_changed, or zoom_changed. These events allow
you to detect changes in the map's state, such as when the map viewport changes or
when the user zooms in or out.
3. Marker Events: When working with markers on the map, you can define callbacks for
various marker events such as click, mouseover, or drag. These callbacks allow you to
respond to user interactions with markers, such as when a marker is clicked or
dragged.
4. Info Window Events: Info windows are used to display additional information when a
marker is clicked. You can define callbacks for info window events such as closeclick
or domready to customize the behavior of info windows.
5. Polygon, Polyline, and Circle Events: If you're working with polygons, polylines, or
circles on the map, you can define callbacks for events such as click, mouseover, or
drag. These callbacks allow you to respond to user interactions with these map
overlays.
6. Directions Service Callbacks: When using the Directions Service to display routes on
the map, you can define callbacks to handle the response returned by the service,
such as directions_changed to detect changes in the route or error to handle errors.
In Google Maps API, you can control the zoom level and rotation of the map
programmatically. Here's how you can do it:

1. Zoom Control: You can control the zoom level of the map using methods provided by
the Google Maps JavaScript API.

// Get the current zoom level

var zoomLevel = map.getZoom();

// Set the zoom level

map.setZoom(newZoomLevel);

Replace newZoomLevel with the desired zoom level you want to set.

2. Rotation Control: Google Maps JavaScript API does not directly support map
rotation, but you can achieve a similar effect by rotating the map container using CSS
or by using a third-party library.

For example, using CSS:

#map-container {

transform: rotate(45deg);

This rotates the map container by 45 degrees. However, keep in mind that rotating the map
container does not rotate the map controls or markers.

Alternatively, you can use a third-party library like Mapbox GL JS or Leaflet.js if you need
more advanced map rotation capabilities.

Remember that while you can control the zoom level and rotation of the map
programmatically, it's essential to provide a smooth and intuitive user experience. Ensure
that zooming and rotation are accessible and easy to use for your users.

THE LOCATION OBJECT


GET THE CURRENT LOCATION

To get the current location of a user in a mobile application using Google Maps API, you
typically utilize the device's GPS or location services. Here's how you can do it in Android
and iOS applications:
Android (Java/Kotlin):

You need to request permission to access the device's location and then use the Location
Services API to get the current location.

1. Request Location Permission:

Make sure to include the necessary permissions in your AndroidManifest.xml file:

<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />

2. Use Location Services API:

In your activity or fragment, you can use the Fused Location Provider API to
request the last known location:

// Create a FusedLocationProviderClient.
FusedLocationProviderClient fusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);

// Check for permission


if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) ==
PackageManager.PERMISSION_GRANTED) {
// Get the last known location
fusedLocationClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
// Use the location
double latitude = location.getLatitude();
double longitude = location.getLongitude();
}
}
});
}
iOS (Swift):
In iOS, you need to request permission to access the device's location and use the Core
Location framework to get the current location.

1. Request Location Permission:

Add the necessary permissions to your Info.plist file:

<key>NSLocationWhenInUseUsageDescription</key>

<string>We need your location to provide the best experience.</string>

2. Use Core Location Framework:

In your view controller, import CoreLocation and implement CLLocationManagerDelegate:

import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {

let locationManager = CLLocationManager()

override func viewDidLoad() {

super.viewDidLoad()

locationManager.delegate = self

locationManager.requestWhenInUseAuthorization()

locationManager.startUpdatingLocation()

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations:


[CLLocation]) {

guard let location = locations.last else { return }

// Use the location

let latitude = location.coordinate.latitude

let longitude = location.coordinate.longitude

}
By using these methods, you can obtain the current location of the user in your
Android and iOS applications using Google Maps API. Remember to handle cases where the
location might not be available or permission is denied by the user.

GET THE UPDATED LOCATION

To continuously get updated location information in a mobile application using Google Maps
API, you need to implement location updates using either the Android Location API or the
Core Location framework in iOS. Here's how you can achieve that in both platforms:

Android (Java/Kotlin):

1. Request Location Updates:

You can use the requestLocationUpdates() method of the LocationManager class to


receive location updates at a specified interval or distance.

// Define a location listener

LocationListener locationListener = new LocationListener() {

@Override

public void onLocationChanged(Location location) {

// Handle updated location

double latitude = location.getLatitude();

double longitude = location.getLongitude();

@Override

public void onStatusChanged(String provider, int status, Bundle extras) {}

@Override

public void onProviderEnabled(String provider) {}

@Override
public void onProviderDisabled(String provider) {}

};

// Request location updates

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,

MIN_TIME_BETWEEN_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES,
locationListener);

iOS (Swift):

Request Location Updates:

Use the startUpdatingLocation() method of the CLLocationManager class to begin receiving


location updates.

locationManager.delegate = self

locationManager.startUpdatingLocation()

2. Handle Updated Locations:

Implement the didUpdateLocations method of the CLLocationManagerDelegate


protocol to receive updated location information.

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations:


[CLLocation]) {

guard let location = locations.last else { return }

// Handle updated location

let latitude = location.coordinate.latitude

let longitude = location.coordinate.longitude

Ensure you have appropriate permissions set up for location access in both
platforms, and handle any potential errors or permission denials gracefully. Continuous
location updates can impact battery life, so use them judiciously and consider adjusting the
update frequency based on your application's needs.

You might also like