Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sensor_server
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
sensor_server
Commits
c347b0fb
Commit
c347b0fb
authored
Sep 06, 2019
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Requesting GPS if it was not running already
parent
f689fb71
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
3 deletions
+51
-3
SensorsUpdate.java
src/com/elphel/sensorserver/SensorsUpdate.java
+51
-3
No files found.
src/com/elphel/sensorserver/SensorsUpdate.java
View file @
c347b0fb
...
@@ -33,10 +33,15 @@ import android.hardware.SensorEvent;
...
@@ -33,10 +33,15 @@ import android.hardware.SensorEvent;
import
android.hardware.SensorEventListener
;
import
android.hardware.SensorEventListener
;
import
android.hardware.SensorManager
;
import
android.hardware.SensorManager
;
import
android.location.Location
;
import
android.location.Location
;
import
android.location.LocationListener
;
import
android.location.LocationManager
;
import
android.location.LocationManager
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.util.Log
;
public
class
SensorsUpdate
implements
SensorEventListener
{
public
class
SensorsUpdate
implements
SensorEventListener
{
private
double
longitude
=
Double
.
NaN
;
private
double
latitude
=
Double
.
NaN
;;
private
static
String
TAG
=
"SENSORS"
;
private
static
String
TAG
=
"SENSORS"
;
private
final
Activity
activity
;
private
final
Activity
activity
;
...
@@ -102,6 +107,16 @@ public class SensorsUpdate implements SensorEventListener{
...
@@ -102,6 +107,16 @@ public class SensorsUpdate implements SensorEventListener{
public
void
pause
()
{
public
void
pause
()
{
sensorManager
.
unregisterListener
(
this
);
sensorManager
.
unregisterListener
(
this
);
LocationManager
lm
=
(
LocationManager
)
activity
.
getSystemService
(
Context
.
LOCATION_SERVICE
);
boolean
isGPSEnabled
=
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
);
if
(
isGPSEnabled
)
{
lm
.
removeUpdates
(
locationListener
);
Log
.
d
(
TAG
,
"Removed GPS updates"
);
}
}
}
private
void
updateOrientationAngles
()
{
private
void
updateOrientationAngles
()
{
...
@@ -124,20 +139,53 @@ public class SensorsUpdate implements SensorEventListener{
...
@@ -124,20 +139,53 @@ public class SensorsUpdate implements SensorEventListener{
}
}
public
double
[]
getLocation
()
{
public
double
[]
getLocation
()
{
double
longitude
=
Double
.
NaN
;
//
double longitude = Double.NaN;
double
latitude
=
Double
.
NaN
;;
//
double latitude = Double.NaN;;
try
{
try
{
LocationManager
lm
=
(
LocationManager
)
activity
.
getSystemService
(
Context
.
LOCATION_SERVICE
);
LocationManager
lm
=
(
LocationManager
)
activity
.
getSystemService
(
Context
.
LOCATION_SERVICE
);
boolean
isGPSEnabled
=
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
);
Log
.
i
(
TAG
,
"Got LocationManager: "
+
lm
.
toString
()+
", isGPSEnabled = "
+
isGPSEnabled
);
Location
location
=
lm
.
getLastKnownLocation
(
LocationManager
.
GPS_PROVIDER
);
Location
location
=
lm
.
getLastKnownLocation
(
LocationManager
.
GPS_PROVIDER
);
if
(
isGPSEnabled
&&
(
location
==
null
))
{
Log
.
d
(
TAG
,
"Requested GPS Updates"
);
lm
.
requestLocationUpdates
(
LocationManager
.
GPS_PROVIDER
,
2000
,
10
,
locationListener
);
}
Log
.
i
(
TAG
,
"Got Location: "
+
location
);
longitude
=
location
.
getLongitude
();
longitude
=
location
.
getLongitude
();
latitude
=
location
.
getLatitude
();
latitude
=
location
.
getLatitude
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Problem getting longitude/latitude
"
);
Log
.
e
(
TAG
,
"Problem getting longitude/latitude
: "
+
e
.
toString
()
);
}
}
double
[]
thisLocation
=
{
longitude
,
latitude
};
double
[]
thisLocation
=
{
longitude
,
latitude
};
return
thisLocation
;
return
thisLocation
;
}
}
// Should be unregistered somehow on pause?
private
final
LocationListener
locationListener
=
new
LocationListener
()
{
@Override
public
void
onLocationChanged
(
Location
location
)
{
longitude
=
location
.
getLongitude
();
latitude
=
location
.
getLatitude
();
}
@Override
public
void
onProviderDisabled
(
String
provider
)
{
// TODO Auto-generated method stub
}
@Override
public
void
onProviderEnabled
(
String
provider
)
{
// TODO Auto-generated method stub
}
@Override
public
void
onStatusChanged
(
String
provider
,
int
status
,
Bundle
extras
)
{
// TODO Auto-generated method stub
}
};
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment