Beruflich Dokumente
Kultur Dokumente
Android
Loca+on
Based
Services
It is a radio-naviga+on system consis+ng of 24 satellites orbi+ng the earth, and their respec+ve ground sta+ons. To calculate a posi+on, these satellites serve as reference points when calcula+ng posi+ons rela+ve to a maEer of meters. In other words, GPS triangulates the posi+on of a satellite, its ground sta+on and the area you want to locate. However, this is done in a more scien+c and nite measurement of travel +me, distance, signal experiences, and atmospheric delays. To measure GPS points, you must use a GPS receiver that calculates its posi+on by the signals transmiEed to the satellites. These satellites send messages containing informa+on such as the +me the message was sent and the satellites orbital informa+on. Once it receives this informa+on, the GPS receiver will then measure the transit +me of the sent message and calculate the distance of the GPS receiver to the each of the satellites. The loca+on is then displayed through GPS maps
GPS
Cell
tower
An
alterna+ve
method
to
determine
the
loca+on
of
a
cell
phone
is
to
es+mate
its
distance
to
three
nearby
cell
towers.
Distance
of
the
phone
to
each
antenna
could
be
es2mated
based
upon
the
lag
2me
between
the
moment
the
tower
sends
a
ping
to
the
phone
and
receives
the
answering
ping
back.
Obtain your current loca+on Track Movement Set proximity alerts for detec+ng movement into and out of a specied area
Loca+on
Provider
Depending
on
the
device,
there
may
be
several
technologies
that
Android
can
use
to
determine
the
current
loca+on
Each
technology,
or
Loca+on
Provider,
will
oer
dierent
capabili+es
including
power
consump+on,
monetary
cost,
accuracy,
and
the
ability
to
determine
al+tude,
speed,
or
heading
informa+on
Loca+on
Provider
Loca+onManager
class
includes
sta+c
string
constants
that
return
the
provider
name
for
the
two
most
common
Loca+on
Providers
To
get
a
list
of
names
for
all
the
providers
Loca+onManager.GPS_PROVIDER
Loca+onManager.NETWORK_PROVIDER
Loca+on
Provider
Most
scenarios,
to
explicitly
choose
the
loca+on
provider
to
use
Specify
the
requirements
that
a
provider
must
meet
and
let
Android
determine
the
best
technology
to
use
Use
Criteria
class
to
dictate
the
requirements
of
a
provider
in
terms
of
Accuracy
Power
Cost
Ability
to
return
values
of
al+tude,
speed,
and
bearing
Criteria
Example
E.g.
Criteria
criteria
=
new
Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAl+tudeRequired(
false
);
criteria.setBearingRequired(
false
);
criteria.setSpeedRequired(
false
);
criteria.setCostAllowed(
true
);
String
bestProvider
=
loca+onManager.getBestProvider(
criteria,
true
);
Criteria
If
more
than
one
Loca+on
Provider
matches,
the
one
with
the
greatest
accuracy
is
returned.
If
no
Loca+on
Provider
meet
requirements,
the
criteria
is
loosened,
in
the
following
order:
Power
used
Accuracy
Ability
to
return
bearing,
speed
and
al+tude
Loca+on
Manager
The
purpose
of
LBS
is
to
nd
the
physical
loca+on
of
the
device
Access
to
LBS
sis
handled
using
the
Loca+on
Manager
system
Service.
To
access
the
Loca+on
Manager,
request
an
instance
of
the
LOCATION_SERVICE
using
the
getSystemService
method
E.g.
String
serviceString
=
Context.LOCATION_SERVICE
Loca+onManager
loca+onManager;
loca+onManager
=
(Loca+onManager)
getSystemService(serviceString);
Loca+on
Manager
Before
usage
of
Loca+on
Manager
Add
uses-permission
tags
to
your
manifest
to
support
access
to
the
LBS
hardware
Default
providers
GPS
provider
requires
Fine
permission
Network
provider
requires
Coarse
permission
GPS
Network
Retrieving
Loca+on
Use
getLastKnownLoca+on
method
E.g.
String
provider
=
Loca+onManager.GPS_PROVIDER
Loca+on
loca+on
=
loca+onManager.getLastKnowLoca+on(provider);
Does
not
ask
the
Loca+on
Provider
to
update
the
current
Posi+on.
La+tude
&
Longitude
Bearing
Speed
Time
the
loca+on
x
was
taken
Geocoding
Translate
between
street
addresses
and
longitude/la+tude
map
coordinates.
Geocoding
class
provides
two
geocoding
func+ons:
Forward
Geocoding
Find
the
la+tude
and
longitude
of
an
address
Reverse
Geocoding
Find
the
street
address
for
a
given
la+tude
and
longitude
Geocoding
Results
are
contextualized
using
a
locale
Locale
is
used
to
dene
your
usual
loca+on
and
language
E.g.
Geocoder
geocoder
=
new
Geocoder (
getApplica+onContext(),
Locale.getDefault());
Geocoding func+ons return a list of Address objects List can contain several possible results, up to a limit specied when making the call
Geocoding:
warning
Geocoding
lookups
are
performed
synchronously,
so
they
will
block
the
calling
thread.
Slow
data
connec+ons
can
lead
to
an
Applica+on
Unresponsive
dialog
Best
to
move
lookups
into
a
Service
or
background
thread
Reverse
Geocoding
Returns
street
addresss
for
physical
loca+ons,
specied
by
latutude/longitude
pairs.
Pass
the
target
la+tude
and
longitude
to
Geocoders
getFromLoca+on
method
Return
a
list
of
possible
addresses
Return
null
if
could
not
resolve
any
addresses
Forward
Geocoding
Determines
map
coordinates
for
a
given
loca+on
Call
getFromLoca+onName
on
a
Geocoder
instance
Pass
in
the
loca+on
and
the
maximum
number
of
results
to
return
E.g.
List<Address>
result
=
geocoder.getFromLoca+onName(aStreetAddress,
maxResults);
Returned list of address can include mul+ple possible matches for the named loca+on Each result will include la+tude and longitude and any addi+onal address informa+on avaliable for those coordinates
Forward
geocoding
If
no
matches
are
found,
null
will
be
returned
Availability,
accuracy,
and
granularity
of
geocoding
results
will
depend
en+rely
on
the
database
available
for
the
area
Locale
specied
when
crea+ng
the
geocoder
object
is
par+cularly
important
The
locale
provides
the
geographical
context
for
interpre+ng
search
requests,
as
the
same
loca+on
names
can
exist
in
mul+ple
areas.
Consider
selec+ng
a
regional
Locale
to
help
avoid
place
name
ambiguity
Map-Based
Ac+vi+es
Usage
of
MapView
Feature
an
interac+ve
map
Supports
both
Overlays
and
by
pinning
Views
to
geographical
loca+ons
Oer
control
of
the
map
display,
leong
you
control
the
zoom
loca+on
display
modes
Satellite
Street
Trac
Suppor+ng
classes
MapView
MapAc+vity
Actual
Map
View
Base
class
extended
to
create
a
new
Ac+vity
that
can
include
a
Map
View.
The
MapAc+vity
class
handles
the
applica+on
life
cycle
and
background
service
management
required
for
displaying
maps.
As
a
result,
can
only
use
a
MapView
within
MapAc+vity-derived
Ac+vi+es
Class
used
to
annotate
maps.
Enables
the
usage
of
a
canvas
to
draw
any
number
of
layers
that
are
displayed
on
top
of
a
Map
View
Used
to
control
the
map,
allowing
developers
to
set
the
center
loca+on
and
zoom
levels
A
special
overlay
that
can
be
used
to
display
the
current
posi+on
and
orienta+on
of
the
device
Used
together
to
create
a
layr
of
map
markers,
displayed
using
drawable
with
associated
text.
Overlay
MapController
MyLoca+onOverlay
Google map downloads the map +les on demand Requires permission to use the internet
Example:
Java
public
class
myMap
extends
MapAc+vity
{
private
MapView
mapView;
/**
Called
when
the
ac+vity
is
rst
created.
*/
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView
=
(MapView)ndViewById(R.id.map_view);
}
}
Example:
Xml
<LinearLayout
xmlns:android="h>p://schemas.android.com/apk/res/android"
android:orienta+on="ver2cal"
android:layout_width="ll_parent"
android:layout_height="ll_parent"
>
<com.google.android.maps.MapView
android:id="@+id/map_view"
android:layout_width="ll_parent"
android:layout_height="ll_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0UDG_KZRwXZYEdpMSH1ZAyHbpqWKtw6BgZOyX0Q"
/>
</LinearLayout>
Example:
Manifest
<manifest
xmlns:android="h>p://schemas.android.com/apk/res/android"
package="com.nyp.android.test.myMap"
android:versionCode="1"
android:versionName="1.0">
<applica+on
android:icon="@drawable/icon"
android:label="@string/app_name">
<ac+vity
android:name=".myMap"
android:label="@string/app_name">
<intent-lter>
<ac+on
android:name="android.intent.ac2on.MAIN"
/>
<category
android:name="android.intent.category.LAUNCHER"
/>
</intent-lter>
</ac+vity>
<uses-library
android:name="com.google.android.maps"/>
</applica+on>
<uses-permission
android:name="android.permission.INTERNET"/>
</manifest>
More
examples..
@Prac+cal