الجامعة السعودية االلكترونية
الجامعة السعودية االلكترونية
26/12/2021
College of Computing and
Informatics
Bachelor of Science in Computer
Science
IT487
Mobile Application Development
IT487
Mobile Application Development
Module 13
Geolocation, Maps and Sensors
Contents
1.Where am I?
2.What's around me?
3.Annotating points of interest
4.Sensors overview
5.Motion sensor
6.Position sensor
7.Environment sensor
Weekly Learning
Outcomes
1. Explain about the geolocation and mapping
capabilities of React Native
2. Explain the basic configuration MapView
components
3. Describe various types of sensors
Required Reading
1. Chapter 19 (React and React Native: A
complete hands-on guide to modern web and
mobile development with React.js,3rd Edition,
2020, Adam Boduch, Roy Derks) and Sensors
(Android Developer Website)
Recommended Reading
Geolocation: https:/ / facebook. github. io/ react- native/
docs/ geolocation
React Native maps: https:/ / github. com/ react-
community/ react- native- maps
Where am I?
Where am I?
• The geolocation API is uses by web applications to figure out the location of the
user.
• *geolocation API used by React Native applications because the same API has
been polyfilled in React Native applications.
• This API is useful for getting precise coordinates from the GPS on mobile devices.
• The API information is used to display meaningful location data to the user.
• Unfortunately, the data (latitude خط العرضand longitude ) خط الطولthat's returned
by the geolocation API is of little use on its own.
• For example, latitude and longitude don't mean anything to the user, but you can use this data to look
up something that is of use to the user (i.e. user address information).
• This might be as simple as displaying where the user is currently located.
Where am I?
• Let's implement an example that uses the
geolocation API of React Native to look up
coordinates and then use those coordinates
to look up human-readable location
information from the Google Maps API:
• The goal of this component is to render the
properties returned by the geolocation API
on the screen, as well as look up the user's
specific location, and display it.
• The setPosition() function is used as a
callback in a couple of places. Its job is to set
the state of your component.
• First, setPosition() sets the longitude, latitude
(lat-long) coordinates.
• Normally, you wouldn't display this data directly,
but this is an example that's showing the data
that's available as part of the geolocation API.
Where am I?
• .Second, setPosition() uses the latitude
and longitude values to look up the
name of where the user is currently,
using the Google Maps API.
• The setPosition() callback is used with
getCurrentPosition(), which is
only called once when the component is
mounted.
• You're also using setPosition() with
watchPosition(), which calls the
callback any time the user's position
changes.
Where am I?
• View of the Screen loaded with the
location data:
• The address information that was
fetched is probably more useful in an
application than latitude and longitude
data.
What's around me?
What's around me?
• The MapView component from
react-native-maps is the main tool
you'll use to render maps in your
React Native applications.
• The two Boolean properties that
you've passed to MapView:
1. The showsUserLocation property will
activate the marker on the map,
which denotes the physical location
of the device running this
application.
2. The followUserLocation property
tells the map to update the location
marker as the device moves around.
• The resulting map:
• .The current location of the device is clearly marked on the map.
• .By default, points of interest are also rendered on the map.
• .These are things in close proximity to the user so that they can see what's around them.
• .It's generally a good idea to use the followUserLocation property whenever using showsUserLocation.
• .This makes the map zoom to the region where the user is located.
Annotating points of interest
Annotating points of interest
• Annotations is additional information rendered on top of the basic map geography.
• .You get annotations, by default, when MapView components are rendered.
• .The MapView component can render the user's current location and points of interest
around the user.
• .The challenge here is that you probably want to show points of interest that are relevant
to your application, instead of the points of interest that are rendered by default.
Plotting points
• .Here is you pass annotations to the MapView
component:
• .Setting the showsPointsOfInterest property to false.
• The callout is displayed when the marker is clicked that
shows the location of the place on the map.
• The text is render based on the description property
values given to <MapView.Marker>
My Home
My home at Glengrove Rd
My Work
My Work at Kingston Rd
Sensor's overview
Sensors - overview
• Android-powered devices have built-in sensors that measure motion, orientation, and
various environmental conditions.
• These sensors capable of providing raw data with high precision and accuracy.
• These sensors are useful to monitor three-dimensional device movement or positioning, or
changes in the ambient (around) environment near a device.
• Examples:
1. A game might track readings from a device's gravity sensor to infer complex user gestures
ايماءاتand motions, such as tilt ميالن, shake, rotation, or swing.
2. A weather application use a device's temperature sensor and humidity sensor to calculate
and report the dewpoint.
3. Travel application use the geomagnetic field sensor and accelerometer to report a compass
bearing.
Introduction to Sensors
• The sensor framework provides several classes and interfaces that help you
perform a wide variety of sensor-related tasks.
• Android sensor framework can use to access many types of sensors available
on the device.
• Sensors: hardware-based and some are software-based.
1. Hardware-based sensors are physical components built into a handset or
tablet device.
• Hardware-based sensors derive their data by directly measuring specific environmental
properties, such as acceleration, geomagnetic field strength, or angular change.
2. Software-based sensors are not physical devices.
• Software-based sensors derive their data from one or more of the hardware-based sensors
and are sometimes called virtual sensors or synthetic/fake sensors.
• .The linear acceleration sensor and the gravity sensor are examples of software-based
sensors.
Table 1. Sensor types supported by the Android platform.
Sensor Type Description Common Uses
Measures the acceleration force in m/s 2 that is applied
TYPE_
Hardware to a device on all three physical axes (x, y, and z), Motion detection (shake, tilt, etc.).
ACCELEROMETER
including the force of gravity.
TYPE_ Measures the ambient room temperature in degrees
Hardware Monitoring air temperatures.
AMBIENT_TEMPERATURE Celsius (°C).
.TYPE_ Software or Measures the force of gravity in m/s 2 that is applied to
Motion detection (shake, tilt, etc.).
GRAVITY Hardware a device on all three physical axes (x, y, z).
TYPE_ Measures a device's rate of rotation in rad/s around
Hardware Rotation detection (spin, turn, etc.).
GYROSCOPE each of the three physical axes (x, y, and z).
TYPE_
Hardware Measures the ambient light level (illumination) in lx. Controlling screen brightness.
LIGHT
Measures the acceleration force in m/s 2 that is applied
.TYPE_ Software or Monitoring acceleration along a single
to a device on all three physical axes (x, y, and z),
LINEAR_ACCELERATION Hardware axis.
excluding the force of gravity.
TYPE_ Measures the ambient geomagnetic field for all three
Hardware Creating a compass.
MAGNETIC_FIELD physical axes (x, y, z) in μT.
Table 1. Sensor types supported by the Android platform. Cont…
Measures degrees of rotation that a device makes around all
three physical axes (x, y, z). As of API level 3 you can obtain the
TYPE_
Software inclination matrix and rotation matrix for a device by using the Determining device position.
ORIENTATION
gravity sensor and the geomagnetic field sensor in conjunction
with the getRotationMatrix() method.
TYPE_
Hardware Measures the ambient air pressure in hPa or mbar. Monitoring air pressure changes.
PRESSURE
Measures the proximity of an object in cm relative to the view
TYPE_
Hardware screen of a device. This sensor is typically used to determine Phone position during a call.
PROXIMITY
whether a handset is being held up to a person's ear.
TYPE_
RELATIVE_HUMIDI Hardware Measures the relative ambient humidity in percent (%). Monitoring dewpoint, absolute, and relative humidity.
TY
.TYPE_
Software or Measures the orientation of a device by providing the three
ROTATION_VECTO Motion detection and rotation detection.
Hardware elements of the device's rotation vector.
R
Measures the temperature of the device in degrees Celsius
.TYPE_ (°C). This sensor implementation varies across devices and this
Hardware
TEMPERATURE sensor was replaced with the
TYPE_AMBIENT_TEMPERATURE sensor in API Level 14
Sensors Framework
• We can access these sensors and acquire raw sensor data by using the Android sensor
framework.
• The sensor framework includes the following classes and interfaces:
• SensorManager
Accessing/listing sensors
Registering/unregistering sensor event listeners
Acquiring orientation information
• Sensor
Determining the capability of sensors
• SensorEvent
Providing information about sensor events
Including raw sensor data, sensor, the accuracy, and timestamp.
• SensorEventListener
Containing callbacks to receiving notifications of sensor events
Sensor Coordinate System
• The sensor framework uses a standard 3-axis
coordinate system to express data values.
• X axis – horizontal pointing right
• Y axis – vertical pointing up
• Z axis – pointing toward the outside of the
screen face.
• Coordinate system does not change when
orientation changes.
• getOrientation() method uses to determine
screen rotation.
• remapCoordinateSystem()method use to
map sensor coordinates to screen coordinates.
Motion sensors
Motion sensors
• Motion sensors monitor the motion of a device.
• Includes accelerometers, gravity sensors, gyroscopes تحديد االتجاه, and rotational
vector sensors.
• The sensors' possible architectures vary by sensor type:
1. The gravity, linear acceleration, rotation vector, step counter, and step detector
sensors are either hardware-based OR software-based.
2. .The accelerometer and gyroscope sensors are always hardware-based.
• Software-based sensors: rely on one or more hardware sensors to derive their
data.
• Derive their data either from the accelerometer or from the gyroscope.
Motion sensors
• Motion sensors are useful for monitoring device movement, such as tilt, shake, rotation,
or swing.
• The movement is either:
1. A reflection of direct user input (for example, a user steering a car in a game or a user controlling a ball
in a game).
2. A reflection of the physical environment in which the device is sitting (for example, moving with you while
you drive your car).
• .Motion sensors by themselves are not typically used to monitor device position, but they
can be used with other sensors.
• All of the motion sensors return multi-dimensional arrays of sensor values for each
Sensor Event.
• .For example, during a single sensor event, the accelerometer returns acceleration force data for the
three coordinate axes, and the gyroscope returns rate of rotation data for the three coordinate axes.
Position sensors
Position sensors
• Position sensors measure the physical position of a device.
• Two hardware-based sensors to determine the position of a device:
Geomagnetic field sensor مستشعر المجال المغناطيسيand the accelerometer.
• Proximity sensor: To determine how close the face of a device is to an object
• Most handset and tablet manufacturers include a geomagnetic field sensor.
• .For determining a device's orientation, you can use the readings from the
device's accelerometer and the geomagnetic field sensor.
• .Position sensors do not monitor device movement or motion, such as shake, tilt,
or thrust.
Environment sensors
Environment sensor
• Environment sensors measure various environmental parameters.
• Four sensors to monitor various environmental properties such as temperature,
pressure, illumination/light, and humidity.
• All four environment sensors are hardware-based and are available only if a
device manufacturer has built them into a device.
• With the exception of the light sensor, which most device manufacturers use to control screen
brightness.
• Environment sensors return a single sensor value for each data event.
• For example, the temperature in °C or the pressure in hPa.
• Environment sensors do not typically require any data filtering or data processing.
Thank
You