add demande gps + debut info sur resto

master
Bastien OLLIER 2 years ago
parent af7f2095f4
commit 0a2327dda6

@ -35,16 +35,18 @@ android {
}
//./gradlew build --refresh-dependencies
dependencies {
implementation 'org.maplibre.gl:android-sdk:9.5.2'
//implementation ('org.maplibre.gl:android-sdk:9.5.2')
implementation ('com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.9.0')
//implementation "com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0"
//implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.5.0'
implementation 'androidx.fragment:fragment-ktx:1.5.5'
implementation 'androidx.fragment:fragment-ktx:1.5.6'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.2.0'
implementation 'com.google.android.material:material:1.8.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'

@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"

@ -1,17 +1,40 @@
package fr.iut.mapping
import android.Manifest.permission.ACCESS_COARSE_LOCATION
import android.Manifest.permission.ACCESS_FINE_LOCATION
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment
import com.mapbox.mapboxsdk.Mapbox
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
@RequiresApi(Build.VERSION_CODES.N)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*gps*/
val locationPermissionRequest = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions -> when {
permissions.getOrDefault(ACCESS_FINE_LOCATION, false) -> {
Toast.makeText(this, "Permission fine location Granted", Toast.LENGTH_SHORT).show()
}
permissions.getOrDefault(ACCESS_COARSE_LOCATION, false) -> {
Toast.makeText(this, "Permission COARSE location Granted", Toast.LENGTH_SHORT).show()
} else -> {
Toast.makeText(this, "Denied permission", Toast.LENGTH_SHORT).show()
}
}
}
locationPermissionRequest.launch(arrayOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION))
/*navBar*/
val firstFragment=FirstFragment()
val secondFragment=SecondFragment()
@ -28,9 +51,10 @@ class MainActivity : AppCompatActivity() {
}
private fun setCurrentFragment(fragment: Fragment)=
private fun setCurrentFragment(fragment: Fragment) =
supportFragmentManager.beginTransaction().apply {
replace(R.id.flFragment,fragment)
commit()
}
}

@ -1,50 +1,138 @@
package fr.iut.mapping
import android.location.Location
import android.location.LocationListener
import android.os.Build
import android.os.Bundle
import android.provider.Settings.Global.getString
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment
import com.google.gson.JsonParser
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.MapboxMapOptions
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.plugins.annotation.Symbol
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions
import com.mapbox.mapboxsdk.utils.BitmapUtils
import kotlinx.android.synthetic.main.fragment_map_page.*
//https://maplibre.org/maplibre-gl-native/android/api/index.html
class FirstFragment: Fragment(R.layout.fragment_map_page), LocationListener {
companion object {
private const val MARKER_SELECTED_ICON = "JAWG_ICON"
private const val MARKER_ICON = "MARKER_ICON"
}
class FirstFragment:Fragment(R.layout.fragment_map_page) {
private var mapView: MapView? = null
private var symbolManager: SymbolManager? = null
private var lastSymbol: Symbol? = null
private val locationPermissionCode = 2
// Returns the Jawg url depending on the style given (jawg-streets by default)
// See /res/values/strings which contains the url, the list of styles and your access token.
private fun makeStyleUrl(): String {
print("${getString(R.string.mapbox_style_url)}")
return "${getString(R.string.mapbox_style_url)}";
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreate(savedInstanceState)
Mapbox.getInstance(requireContext())
// Inflate the layout for this fragment
Mapbox.getInstance(requireContext(), R.string.mapbox_access_token.toString())
val rootView = inflater.inflate(R.layout.fragment_map_page, container, false)
// We get the map view to set its style with the desired Jawg url.
mapView = rootView.findViewById(R.id.mapView)
mapView?.onCreate(savedInstanceState)
mapView?.getMapAsync { map ->
map.setStyle(makeStyleUrl()) {
// Map fully loaded in this scope.
// Update attributions position
map.setStyle(makeStyleUrl()) { style ->
map.uiSettings.setAttributionMargins(15, 0, 0, 15)
val selectedMarkerIconDrawable = ResourcesCompat.getDrawable(this.resources, R.drawable.ic_menu_likes, null)
style.addImage(MARKER_ICON, BitmapUtils.getBitmapFromDrawable(selectedMarkerIconDrawable)!!)
val markerIconDrawable = ResourcesCompat.getDrawable(this.resources, R.drawable.ic_menu_likes, null)
style.addImage(MARKER_SELECTED_ICON, BitmapUtils.getBitmapFromDrawable(markerIconDrawable)!!)
// Initialize SymbolManager.
this.symbolManager = SymbolManager(mapView!!, map, style)
this.symbolManager?.iconAllowOverlap = true
this.symbolManager?.iconIgnorePlacement = true
// Insert markers with their associated data.
insertIconOnMap(
LatLng(51.50853, -0.076132),
"Tower of London",
R.drawable.ic_menu_likes,
"It is a historic castle on the north bank of the River Thames in central London." +
"It lies within the London Borough of Tower Hamlets, which is separated from the eastern edge of the square mile of the City of London by the open space known as Tower Hill." +
"It was founded towards the end of 1066 as part of the Norman Conquest of England."
)
// Add a listener to trigger markers clicks.
this.symbolManager?.addClickListener {
// Put all marker information into the layout.
titleView.text = it.data?.asJsonObject?.get("title")?.asString
descriptionView.text = it.data?.asJsonObject?.get("description")?.asString
descriptionLayout.background = ContextCompat.getDrawable(requireContext(),it.data?.asJsonObject?.get("imageId")?.asInt!!)
descriptionLayout.background.alpha = 30
// Set the new marker as selected and toggle layout.
setSelectedIcon(it)
toggleLayout()
true
}
}
}
return rootView
}
private fun toggleLayout() {
mapView?.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 2f)
descriptionLayout?.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f)
}
private fun setDefaultIcon(symbol: Symbol) {
symbol.iconImage = MARKER_ICON
symbol.iconSize = 0.24f
symbolManager?.update(symbol)
}
private fun setSelectedIcon(symbol: Symbol) {
symbol.iconImage = MARKER_SELECTED_ICON
symbol.iconSize = 0.25f
symbolManager?.update(symbol)
if (this.lastSymbol != null) {
setDefaultIcon(this.lastSymbol!!)
}
this.lastSymbol = symbol
}
private fun insertIconOnMap(point: LatLng, title: String, imageId: Int, description: String) {
// Convert datas of the marker into Json object.
val jsonData = """
{
"title" : "$title",
"imageId" : "$imageId",
"description" : "$description"
}
"""
// Add symbol at specified lat/lon.
val newSymbol = symbolManager!!.create(
SymbolOptions()
.withLatLng(LatLng(point.latitude, point.longitude))
.withData(JsonParser.parseString(jsonData))
)
setDefaultIcon(newSymbol)
}
override fun onStart() {
super.onStart()
mapView?.onStart()
@ -74,4 +162,10 @@ class FirstFragment:Fragment(R.layout.fragment_map_page) {
super.onDestroy()
mapView?.onDestroy()
}
//methode pour le GPS
override fun onLocationChanged(location: Location) {
print("Latitude: " + location.latitude + " , Longitude: " + location.longitude)
}
}

@ -1,13 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
xmlns:mapbox="http://schemas.android.com/apk/res-auto">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3">
<LinearLayout
android:id="@+id/mapLayout"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="3">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="51.5"
mapbox:mapbox_cameraTargetLng="-0.11"
mapbox:mapbox_cameraZoom="11"
mapbox:mapbox_uiLogo="false"
mapbox:mapbox_uiAttribution="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/descriptionLayout"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0"
android:weightSum="3"
android:orientation="vertical">
<TextView
android:id="@+id/titleView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:padding="10dp"
android:textSize="30dp"
android:text=" "
android:textAlignment="center"
android:layout_weight="1" />
<TextView
android:id="@+id/descriptionView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:padding="10dp"
android:textSize="15dp"
android:text=" "
android:textAlignment="center"
android:layout_weight="2" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -3,4 +3,4 @@ plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
}

@ -20,5 +20,5 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.enableJetifier=true
android.nonTransitiveRClass=true

@ -10,6 +10,20 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = 'gorky1234'
// Use the secret token you stored in gradle.properties as the password
password = "pk.eyJ1IjoiZ29ya3kxMjM0IiwiYSI6ImNsZm1wY2w3ZTBkZ3EzcG1taXc5c29zYzQifQ.XZFV0wLqNLAgSgwY5C_SpQ"
}
}
jcenter()
}
}
rootProject.name = "Mapping"

Loading…
Cancel
Save