Commit cf6a36b3 authored by Andres Käver's avatar Andres Käver

location line

parent 44e707cc
......@@ -3,6 +3,7 @@ package ee.taltech.mobile2020.gpsmapdemo
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.graphics.Color
import android.location.Criteria
import android.location.Location
import android.location.LocationListener
......@@ -18,14 +19,19 @@ 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.Polyline
import com.google.android.gms.maps.model.PolylineOptions
class MapsActivity : AppCompatActivity(), OnMapReadyCallback, LocationListener {
private lateinit var mMap: GoogleMap
private lateinit var locationManager: LocationManager;
private var provider : String? = "";
private var location: Location? = null;
private var provider : String? = ""
private var location: Location? = null
private val polylineOptions = PolylineOptions().width(5f)
.color(Color.RED)
private lateinit var polyLine : Polyline
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -36,7 +42,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, LocationListener {
provider = locationManager.getBestProvider(criteria, true)
Log.d("Provider", provider);
Log.d("Provider", (provider ?: "null"))
if (provider != null){
if (
......@@ -76,10 +82,11 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, LocationListener {
}
mMap.addMarker(MarkerOptions().position(markerLatLng).title("Marker"))
mMap.moveCamera(CameraUpdateFactory.zoomTo(15f));
mMap.moveCamera(CameraUpdateFactory.zoomTo(17f));
mMap.moveCamera(CameraUpdateFactory.newLatLng(markerLatLng))
}
override fun onResume() {
......@@ -105,6 +112,20 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, LocationListener {
override fun onLocationChanged(location: Location?) {
if (mMap == null) return
var markerLatLng = LatLng(location!!.latitude, location!!.longitude)
// remove the old polyline from map
// or you will just add lines on top of each other and run out of memory
if (polyLine != null) {
polyLine.remove();
}
polylineOptions.add(markerLatLng)
polyLine = mMap.addPolyline(polylineOptions)
// polyLine.points.add(markerLatLng);
// mMap.addMarker(MarkerOptions().position(markerLatLng).title("Marker"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(markerLatLng))
}
......
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