Commit 317807b0 authored by Andres Käver's avatar Andres Käver
Browse files

some drawings on maps

parent b605075e
......@@ -11,6 +11,11 @@ class C {
const val LOCATION_UPDATE_ACTION = PREFIX + "location_update"
const val LOCATION_UPDATE_STOP = PREFIX + "location_stop"
const val LOCATION_UPDATE_ACTION_LAT = PREFIX + "location_update.lat"
const val LOCATION_UPDATE_ACTION_LON = PREFIX + "location_update.lon"
const val LOCATION_UPDATE_ACTION_OVERALL_DIRECT = PREFIX + "location_update.overall_direct"
const val LOCATION_UPDATE_ACTION_OVERALL_TOTAL = PREFIX + "location_update.overall_total"
const val LOCATION_UPDATE_ACTION_CP_DIRECT = PREFIX + "location_update.cp_direct"
......
......@@ -235,6 +235,10 @@ class LocationService : Service() {
// broadcast new location to UI
val intent = Intent(C.LOCATION_UPDATE_ACTION)
intent.putExtra(C.LOCATION_UPDATE_ACTION_LAT, location.latitude)
intent.putExtra(C.LOCATION_UPDATE_ACTION_LON, location.longitude)
intent.putExtra(C.LOCATION_UPDATE_ACTION_OVERALL_DIRECT, distanceOverallDirect)
intent.putExtra(C.LOCATION_UPDATE_ACTION_OVERALL_TOTAL, distanceOverallTotal)
intent.putExtra(C.LOCATION_UPDATE_ACTION_CP_DIRECT, distanceCPDirect)
......@@ -288,7 +292,7 @@ class LocationService : Service() {
// broadcast stop to UI
val intent = Intent(C.LOCATION_UPDATE_ACTION)
val intent = Intent(C.LOCATION_UPDATE_STOP)
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
}
......
......@@ -24,8 +24,7 @@ import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.gms.maps.model.*
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.map_actions.*
......@@ -35,12 +34,12 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
}
private lateinit var mMap: GoogleMap
private var marker: Marker? = null
private var mapPolylineOptions: PolylineOptions = PolylineOptions()
private var mapPolyline : Polyline? = null
private val broadcastReceiver = InnerBroadcastReceiver()
private val broadcastReceiverIntentFilter: IntentFilter = IntentFilter()
private var locationServiceActive = false
......@@ -108,12 +107,35 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
mMap = googleMap
// Add a marker in Sydney and move the camera
val sydney = LatLng(-34.0, 151.0)
mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
//val sydney = LatLng(-34.0, 151.0)
//mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng( LatLng(59.3927437,24.6642)))
mMap.animateCamera(CameraUpdateFactory.zoomTo(17.0f))
}
private fun updateMap(lat: Double, lon: Double){
// mMap.clear()
val center = LatLng(lat, lon)
if (marker != null ){
marker!!.remove()
}
if (mapPolyline != null ){
mapPolyline!!.remove()
}
mapPolylineOptions.add(center)
marker = mMap.addMarker(MarkerOptions().position(center).icon(BitmapDescriptorFactory.fromResource(R.drawable.baseline_location_searching_black_36)))
mapPolyline = mMap.addPolyline(mapPolylineOptions)
mMap.moveCamera(CameraUpdateFactory.newLatLng(center))
}
// ============================================== LIFECYCLE CALLBACKS =============================================
override fun onStart() {
Log.d(TAG, "onStart")
......@@ -272,6 +294,10 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
textViewCPTotal.text = intent.getFloatExtra(C.LOCATION_UPDATE_ACTION_CP_TOTAL, 0.0f).toInt().toString()
textViewWPDirect.text = intent.getFloatExtra(C.LOCATION_UPDATE_ACTION_WP_DIRECT, 0.0f).toInt().toString()
textViewWPTotal.text = intent.getFloatExtra(C.LOCATION_UPDATE_ACTION_WP_TOTAL, 0.0f).toInt().toString()
updateMap(intent.getDoubleExtra(C.LOCATION_UPDATE_ACTION_LAT, 0.0), intent.getDoubleExtra(C.LOCATION_UPDATE_ACTION_LON, 0.0))
}
C.LOCATION_UPDATE_STOP -> {
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment