Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
L
location share white
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
location share white
Commits
20af04a0
Commit
20af04a0
authored
Oct 30, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
fbb79620
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
28 deletions
+59
-28
LocationMapActivity.kt
.../locationsharewhite/ui/locationmap/LocationMapActivity.kt
+39
-23
LocationPresenter.kt
...se/locationsharewhite/ui/locationmap/LocationPresenter.kt
+20
-5
No files found.
app/src/main/java/com/base/locationsharewhite/ui/locationmap/LocationMapActivity.kt
View file @
20af04a0
...
...
@@ -82,9 +82,10 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
if
(
currentViewingBean
!=
viewingBean
)
{
removeOldViewingMarker
()
currentViewingBean
=
viewingBean
setViewingBeanMarker
(
15f
)
}
changeMarkerZIndex
(
false
)
setViewingBeanMarker
(
true
)
startGetLocationJob
()
},
...
...
@@ -116,7 +117,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
viewing
?.
locatDate
=
locatDate
adapter
.
notifyDataSetChanged
()
setViewingBeanMarker
()
setViewingBeanMarker
(
false
)
}
}
}
...
...
@@ -180,9 +181,8 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
binding
.
llNoFriend
.
visibility
=
View
.
VISIBLE
}
}
binding
.
ivLocation
.
setOnClickListener
{
resetMyLocation
()
resetMyLocation
(
locationPresenter
.
getMyLocation
(),
true
,
true
)
}
binding
.
ivRefresh
.
setOnClickListener
{
startRefreshAnimation
()
...
...
@@ -223,35 +223,38 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
override
fun
onMapReady
(
googleMap
:
GoogleMap
)
{
map
=
googleMap
LogEx
.
logDebug
(
TAG
,
"onMapReady"
)
val
flag
=
resetMyLocation
()
val
flag
=
resetMyLocation
(
locationPresenter
.
getMyLocation
(),
true
,
true
)
if
(!
flag
)
{
locationPresenter
.
getGoogleServiceLocation
()
locationPresenter
.
oneShotLocationCallBack
=
{
resetMyLocation
()
}
resetMyLocation
(
locationPresenter
.
getMyLocation
(),
true
,
true
)
}
}
private
fun
resetMyLocation
():
Boolean
{
var
myLatLng
:
LatLng
?
=
getLatLngByLocationManager
()
if
(
myLatLng
==
null
)
{
myLatLng
=
locationPresenter
.
googleLocation
locationPresenter
.
refreshLocationCallBack
=
{
resetMyLocation
(
it
,
false
,
false
)
}
if
(
BuildConfig
.
DEBUG
)
{
if
(
myLatLng
==
null
)
{
toast
(
"can't get LatLng"
)
}
private
fun
resetMyLocation
(
latLng
:
LatLng
?,
resetZoom
:
Boolean
,
changeZIndex
:
Boolean
):
Boolean
{
if
(
changeZIndex
)
{
changeMarkerZIndex
(
true
)
}
initMyLocationMarker
()
myLatLng
?.
let
{
myMarker
?.
position
=
myLatLng
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
myLatLng
,
15f
))
latLng
?.
let
{
myMarker
?.
position
=
it
if
(
resetZoom
)
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
it
,
15f
))
}
else
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLng
(
it
))
}
return
true
}
return
false
}
private
fun
initMyLocationMarker
()
{
if
(
myMarker
==
null
)
{
var
myLatLng
:
LatLng
?
=
getLatLngByLocationManager
()
...
...
@@ -266,7 +269,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
}
}
private
fun
setViewingBeanMarker
(
zoom
:
Float
?
=
null
)
{
private
fun
setViewingBeanMarker
(
resetZoom
:
Boolean
)
{
currentViewingBean
?.
let
{
viewingBean
->
viewingBean
.
locatDate
?.
let
{
locatDate
->
...
...
@@ -278,7 +281,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
friendMarker
=
map
?.
addLocationMarker
(
friendAvatar
,
latLng
,
viewingBean
.
nickname
)
}
setView
BeanLocation
(
latLng
,
z
oom
)
setView
ingBeanLocation
(
latLng
,
resetZ
oom
)
}
}
}
...
...
@@ -288,11 +291,24 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
friendMarker
=
null
}
private
fun
setViewBeanLocation
(
latLng
:
LatLng
,
zoom
:
Float
?
=
null
)
{
zoom
?.
let
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
latLng
,
it
))
private
fun
setViewingBeanLocation
(
latLng
:
LatLng
,
resetZoom
:
Boolean
=
false
)
{
if
(
resetZoom
)
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
latLng
,
15f
))
}
else
{
map
?.
moveCamera
(
CameraUpdateFactory
.
newLatLng
(
latLng
))
}
myMarker
?.
position
=
latLng
}
private
fun
changeMarkerZIndex
(
isShowMe
:
Boolean
)
{
if
(
isShowMe
)
{
myMarker
?.
zIndex
=
2f
friendMarker
?.
zIndex
=
1f
}
else
{
myMarker
?.
zIndex
=
1f
friendMarker
?.
zIndex
=
2f
}
}
...
...
app/src/main/java/com/base/locationsharewhite/ui/locationmap/LocationPresenter.kt
View file @
20af04a0
...
...
@@ -33,20 +33,35 @@ class LocationPresenter(
private
var
fusedLocationClient
:
FusedLocationProviderClient
=
LocationServices
.
getFusedLocationProviderClient
(
activity
)
var
googleLocation
:
LatLng
?
=
null
//一次性更新自己的位置
var
oneShotLocationCallBack
:
(()
->
Unit
)?
=
null
//刷新自己的位置
var
refreshLocationCallBack
:
((
latLng
:
LatLng
?)
->
Unit
)?
=
null
fun
getMyLocation
():
LatLng
?
{
var
latLng
=
activity
.
getLatLngByLocationManager
()
if
(
latLng
==
null
)
{
latLng
=
googleLocation
}
return
latLng
}
fun
startUploadMyLocation
()
{
if
(
uploadJob
==
null
)
{
uploadJob
=
lifecycleCoroutineScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
isActive
)
{
getGoogleServiceLocation
()
var
latLng
=
activity
.
getLatLngByLocationManager
()
if
(
latLng
==
null
)
{
latLng
=
googleLocation
}
val
latLng
=
getMyLocation
()
val
power
=
activity
.
getBatteryLevel
()
latLng
?.
let
{
uploadMyLocation
(
latLng
,
power
)
}
latLng
?.
let
{
launch
(
Dispatchers
.
Main
)
{
refreshLocationCallBack
?.
invoke
(
it
)
}
uploadMyLocation
(
latLng
,
power
)
}
delay
(
30
*
1000L
)
}
}
...
...
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