diff --git a/app/src/main/java/com/example/sungdongwalk/components/map/MapView.kt b/app/src/main/java/com/example/sungdongwalk/components/map/MapView.kt new file mode 100644 index 0000000..1eaa4e8 --- /dev/null +++ b/app/src/main/java/com/example/sungdongwalk/components/map/MapView.kt @@ -0,0 +1,53 @@ +package com.example.sungdongwalk.components.map + +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import com.example.sungdongwalk.R +import com.example.sungdongwalk.activities.MainActivity +import com.example.sungdongwalk.viewmodels.PlaceViewModel +import com.naver.maps.geometry.LatLng +import com.naver.maps.map.compose.ExperimentalNaverMapApi +import com.naver.maps.map.compose.LocationTrackingMode +import com.naver.maps.map.compose.MapProperties +import com.naver.maps.map.compose.MapType +import com.naver.maps.map.compose.MapUiSettings +import com.naver.maps.map.compose.Marker +import com.naver.maps.map.compose.MarkerState +import com.naver.maps.map.compose.NaverMap +import com.naver.maps.map.overlay.OverlayImage + +@OptIn(ExperimentalNaverMapApi::class) +@Composable +fun MapView(){ + NaverMap( + locationSource = MainActivity.locationSource, + modifier = Modifier + .fillMaxSize(), + uiSettings = MapUiSettings( + isCompassEnabled = true, + isLocationButtonEnabled = true, + isScrollGesturesEnabled = true, + isScaleBarEnabled = true, + isIndoorLevelPickerEnabled = true, + isLogoClickEnabled = true + ), + properties = MapProperties( + mapType = MapType.Basic, + isIndoorEnabled = true, + locationTrackingMode = LocationTrackingMode.Follow, + ), + ){ + PlaceViewModel.instance.markers.value.forEach { place -> + Marker( + icon = OverlayImage.fromResource(if(place.hasEvent) R.drawable.pin_event else R.drawable.pin_default), + state = MarkerState(position = LatLng( + place.ycoordinate.toDouble(), + place.xcoordinate.toDouble() + )), + captionText = place.name, + ) + } + } + +} diff --git a/app/src/main/java/com/example/sungdongwalk/location/LocationManager.kt b/app/src/main/java/com/example/sungdongwalk/location/LocationManager.kt new file mode 100644 index 0000000..3478b69 --- /dev/null +++ b/app/src/main/java/com/example/sungdongwalk/location/LocationManager.kt @@ -0,0 +1,18 @@ +package com.example.sungdongwalk.location + +import android.annotation.SuppressLint +import com.example.sungdongwalk.viewmodels.LocationViewModel +import com.google.android.gms.location.FusedLocationProviderClient + +class LocationManager(private val locationClient: FusedLocationProviderClient) { + + @SuppressLint("MissingPermission") + fun getLastLocation(){ + locationClient.lastLocation + .addOnSuccessListener {location -> + if(location != null){ + LocationViewModel.instance.updateLocation(location.longitude, location.latitude) + } + } + } +} \ No newline at end of file