Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-plugin-background-geolocation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Aksimaya
cordova-plugin-background-geolocation
Commits
ab3c2fad
Commit
ab3c2fad
authored
Aug 31, 2014
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement bug fixes for isses 63 (add altitude, bearing) & 38 (post in ISO-8601 foramt)
parent
b6614822
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
18 deletions
+51
-18
LocationUpdateService.java
src/android/LocationUpdateService.java
+14
-10
Location.java
src/android/data/Location.java
+17
-1
LocationDAO.java
src/android/data/LocationDAO.java
+6
-3
LocationOpenHelper.java
src/android/data/sqlite/LocationOpenHelper.java
+2
-0
SQLiteLocationDAO.java
src/android/data/sqlite/SQLiteLocationDAO.java
+12
-4
No files found.
src/android/LocationUpdateService.java
View file @
ab3c2fad
...
...
@@ -493,7 +493,7 @@ public class LocationUpdateService extends Service implements LocationListener {
if
(
isDebugging
)
{
startTone
(
"beep"
);
}
float
distance
=
abs
(
location
.
distanceTo
(
stationaryLocation
)
-
stationaryLocation
.
getAccuracy
()
-
location
.
getAccuracy
());
float
distance
=
abs
(
location
.
distanceTo
(
stationaryLocation
)
-
stationaryLocation
.
getAccuracy
()
-
location
.
getAccuracy
());
if
(
isDebugging
)
{
Toast
.
makeText
(
this
,
"Stationary exit in "
+
(
stationaryRadius
-
distance
)
+
"m"
,
Toast
.
LENGTH_LONG
).
show
();
...
...
@@ -650,7 +650,7 @@ public class LocationUpdateService extends Service implements LocationListener {
Log
.
d
(
TAG
,
"afterexecute "
+
task
.
getStatus
());
}
private
boolean
postLocation
(
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
.
Location
l
)
{
private
boolean
postLocation
(
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
.
Location
l
,
LocationDAO
dao
)
{
if
(
l
==
null
)
{
Log
.
w
(
TAG
,
"postLocation: null location"
);
return
false
;
...
...
@@ -666,9 +666,13 @@ public class LocationUpdateService extends Service implements LocationListener {
location
.
put
(
"longitude"
,
l
.
getLongitude
());
location
.
put
(
"accuracy"
,
l
.
getAccuracy
());
location
.
put
(
"speed"
,
l
.
getSpeed
());
location
.
put
(
"recorded_at"
,
l
.
getRecordedAt
());
location
.
put
(
"bearing"
,
l
.
getBearing
());
location
.
put
(
"altitude"
,
l
.
getAltitude
());
location
.
put
(
"recorded_at"
,
dao
.
dateToString
(
l
.
getRecordedAt
()));
params
.
put
(
"location"
,
location
);
Log
.
i
(
TAG
,
"location: "
+
location
.
toString
());
StringEntity
se
=
new
StringEntity
(
params
.
toString
());
request
.
setEntity
(
se
);
request
.
setHeader
(
"Accept"
,
"application/json"
);
...
...
@@ -676,11 +680,11 @@ public class LocationUpdateService extends Service implements LocationListener {
Iterator
<
String
>
headkeys
=
headers
.
keys
();
while
(
headkeys
.
hasNext
()
){
String
headkey
=
headkeys
.
next
();
if
(
headkey
!=
null
)
{
Log
.
d
(
TAG
,
"Adding Header: "
+
headkey
+
" : "
+
(
String
)
headers
.
getString
(
headkey
));
request
.
setHeader
(
headkey
,
(
String
)
headers
.
getString
(
headkey
));
}
String
headkey
=
headkeys
.
next
();
if
(
headkey
!=
null
)
{
Log
.
d
(
TAG
,
"Adding Header: "
+
headkey
+
" : "
+
(
String
)
headers
.
getString
(
headkey
));
request
.
setHeader
(
headkey
,
(
String
)
headers
.
getString
(
headkey
));
}
}
Log
.
d
(
TAG
,
"Posting to "
+
request
.
getURI
().
toString
());
HttpResponse
response
=
httpClient
.
execute
(
request
);
...
...
@@ -761,7 +765,7 @@ public class LocationUpdateService extends Service implements LocationListener {
LocationDAO
locationDAO
=
DAOFactory
.
createLocationDAO
(
LocationUpdateService
.
this
.
getApplicationContext
());
for
(
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
.
Location
savedLocation
:
locationDAO
.
getAllLocations
())
{
Log
.
d
(
TAG
,
"Posting saved location"
);
if
(
postLocation
(
savedLocation
))
{
if
(
postLocation
(
savedLocation
,
locationDAO
))
{
locationDAO
.
deleteLocation
(
savedLocation
);
}
}
...
...
src/android/data/Location.java
View file @
ab3c2fad
...
...
@@ -11,7 +11,9 @@ public class Location {
private
Date
recordedAt
;
private
String
accuracy
;
private
String
speed
;
private
String
altitude
;
private
String
bearing
;
private
Long
id
;
public
Long
getId
()
{
...
...
@@ -50,6 +52,18 @@ public class Location {
public
void
setSpeed
(
String
speed
)
{
this
.
speed
=
speed
;
}
public
String
getBearing
()
{
return
bearing
;
}
public
void
setBearing
(
String
bearing
)
{
this
.
bearing
=
bearing
;
}
public
String
getAltitude
()
{
return
altitude
;
}
public
void
setAltitude
(
String
altitude
)
{
this
.
altitude
=
altitude
;
}
public
static
Location
fromAndroidLocation
(
android
.
location
.
Location
originalLocation
)
{
Location
location
=
new
Location
();
...
...
@@ -58,6 +72,8 @@ public class Location {
location
.
setLatitude
(
String
.
valueOf
(
originalLocation
.
getLatitude
()));
location
.
setAccuracy
(
String
.
valueOf
(
originalLocation
.
getAccuracy
()));
location
.
setSpeed
(
String
.
valueOf
(
originalLocation
.
getSpeed
()));
location
.
setBearing
(
String
.
valueOf
(
originalLocation
.
getBearing
()));
location
.
setAltitude
(
String
.
valueOf
(
originalLocation
.
getAltitude
()));
return
location
;
}
...
...
src/android/data/LocationDAO.java
View file @
ab3c2fad
package
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
;
import
java.util.Date
;
public
interface
LocationDAO
{
public
Location
[]
getAllLocations
();
public
boolean
persistLocation
(
Location
l
);
public
void
deleteLocation
(
Location
l
);
public
Location
[]
getAllLocations
();
public
boolean
persistLocation
(
Location
l
);
public
void
deleteLocation
(
Location
l
);
public
String
dateToString
(
Date
date
);
}
src/android/data/sqlite/LocationOpenHelper.java
View file @
ab3c2fad
...
...
@@ -15,6 +15,8 @@ public class LocationOpenHelper extends SQLiteOpenHelper {
" recordedAt TEXT,"
+
" accuracy TEXT,"
+
" speed TEXT,"
+
" bearing TEXT,"
+
" altitude TEXT,"
+
" latitude TEXT,"
+
" longitude TEXT"
;
private
static
final
String
LOCATION_TABLE_CREATE
=
...
...
src/android/data/sqlite/SQLiteLocationDAO.java
View file @
ab3c2fad
...
...
@@ -4,6 +4,7 @@ import java.text.ParseException;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.TimeZone
;
import
java.util.List
;
import
android.content.ContentValues
;
...
...
@@ -16,7 +17,7 @@ import com.tenforwardconsulting.cordova.bgloc.data.Location;
import
com.tenforwardconsulting.cordova.bgloc.data.LocationDAO
;
public
class
SQLiteLocationDAO
implements
LocationDAO
{
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd
HH:mm:ss
"
;
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd
'T'HH:mm'Z'
"
;
private
static
final
String
TAG
=
"SQLiteLocationDAO"
;
private
Context
context
;
...
...
@@ -80,6 +81,8 @@ public class SQLiteLocationDAO implements LocationDAO {
l
.
setLongitude
(
c
.
getString
(
c
.
getColumnIndex
(
"longitude"
)));
l
.
setAccuracy
(
c
.
getString
(
c
.
getColumnIndex
(
"accuracy"
)));
l
.
setSpeed
(
c
.
getString
(
c
.
getColumnIndex
(
"speed"
)));
l
.
setAltitude
(
c
.
getString
(
c
.
getColumnIndex
(
"altitude"
)));
l
.
setBearing
(
c
.
getString
(
c
.
getColumnIndex
(
"bearing"
)));
return
l
;
}
...
...
@@ -90,26 +93,31 @@ public class SQLiteLocationDAO implements LocationDAO {
values
.
put
(
"longitude"
,
location
.
getLongitude
());
values
.
put
(
"recordedAt"
,
dateToString
(
location
.
getRecordedAt
()));
values
.
put
(
"accuracy"
,
location
.
getAccuracy
());
values
.
put
(
"altitude"
,
location
.
getAltitude
());
values
.
put
(
"bearing"
,
location
.
getBearing
());
values
.
put
(
"speed"
,
location
.
getSpeed
());
return
values
;
}
public
Date
stringToDate
(
String
dateTime
)
{
TimeZone
tz
=
TimeZone
.
getTimeZone
(
"UTC"
);
SimpleDateFormat
iso8601Format
=
new
SimpleDateFormat
(
DATE_FORMAT
);
iso8601Format
.
setTimeZone
(
tz
);
Date
date
=
null
;
try
{
date
=
iso8601Format
.
parse
(
dateTime
);
date
=
iso8601Format
.
parse
(
dateTime
);
}
catch
(
ParseException
e
)
{
Log
.
e
(
"DBUtil"
,
"Parsing ISO8601 datetime ("
+
dateTime
+
") failed"
,
e
);
}
return
date
;
}
public
String
dateToString
(
Date
date
)
{
TimeZone
tz
=
TimeZone
.
getTimeZone
(
"UTC"
);
SimpleDateFormat
iso8601Format
=
new
SimpleDateFormat
(
DATE_FORMAT
);
iso8601Format
.
setTimeZone
(
tz
);
return
iso8601Format
.
format
(
date
);
}
...
...
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