Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MOBAPP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
THONG Sylvain
MOBAPP
Commits
9e2d7a51
"...Wishlist-application.git" did not exist on "0381d8953e25081fd3f89876656388fae9e54a25"
Commit
9e2d7a51
authored
2 months ago
by
COUCHET Thibaud
Browse files
Options
Downloads
Patches
Plain Diff
App with maps work without intraction plus riches
parent
8115bdb4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/fr/imt_atlantique/myfirstapplication/MapsFragment.java
+57
-3
57 additions, 3 deletions
...va/fr/imt_atlantique/myfirstapplication/MapsFragment.java
with
57 additions
and
3 deletions
app/src/main/java/fr/imt_atlantique/myfirstapplication/MapsFragment.java
+
57
−
3
View file @
9e2d7a51
...
@@ -21,12 +21,17 @@ import com.google.android.gms.maps.CameraUpdateFactory;
...
@@ -21,12 +21,17 @@ import com.google.android.gms.maps.CameraUpdateFactory;
import
com.google.android.gms.maps.GoogleMap
;
import
com.google.android.gms.maps.GoogleMap
;
import
com.google.android.gms.maps.OnMapReadyCallback
;
import
com.google.android.gms.maps.OnMapReadyCallback
;
import
com.google.android.gms.maps.SupportMapFragment
;
import
com.google.android.gms.maps.SupportMapFragment
;
import
com.google.android.gms.maps.model.CameraPosition
;
import
com.google.android.gms.maps.model.LatLng
;
import
com.google.android.gms.maps.model.LatLng
;
import
com.google.android.gms.maps.model.MarkerOptions
;
import
com.google.android.gms.maps.model.MarkerOptions
;
import
java.util.ArrayList
;
public
class
MapsFragment
extends
Fragment
{
public
class
MapsFragment
extends
Fragment
{
private
Toolbar
toolbar
;
private
Toolbar
toolbar
;
private
GoogleMap
mMap
;
private
final
ArrayList
<
LatLng
>
markerPositions
=
new
ArrayList
<>();
public
MapsFragment
()
{
public
MapsFragment
()
{
// Required empty public constructor
// Required empty public constructor
...
@@ -49,6 +54,12 @@ public class MapsFragment extends Fragment {
...
@@ -49,6 +54,12 @@ public class MapsFragment extends Fragment {
*/
*/
@Override
@Override
public
void
onMapReady
(
GoogleMap
googleMap
)
{
public
void
onMapReady
(
GoogleMap
googleMap
)
{
mMap
=
googleMap
;
// Redessine les anciens marqueurs si existants
for
(
LatLng
position
:
markerPositions
)
{
googleMap
.
addMarker
(
new
MarkerOptions
().
position
(
position
)
.
title
(
"Lat: "
+
position
.
latitude
+
", Lng: "
+
position
.
longitude
));
}
// We check for the application "Call permission"
// We check for the application "Call permission"
if
(
ContextCompat
.
checkSelfPermission
(
requireContext
(),
if
(
ContextCompat
.
checkSelfPermission
(
requireContext
(),
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
...
@@ -60,6 +71,37 @@ public class MapsFragment extends Fragment {
...
@@ -60,6 +71,37 @@ public class MapsFragment extends Fragment {
googleMap
.
getUiSettings
().
setZoomGesturesEnabled
(
true
);
googleMap
.
getUiSettings
().
setZoomGesturesEnabled
(
true
);
googleMap
.
getUiSettings
().
setCompassEnabled
(
true
);
googleMap
.
getUiSettings
().
setCompassEnabled
(
true
);
googleMap
.
getUiSettings
().
setMyLocationButtonEnabled
(
true
);
googleMap
.
getUiSettings
().
setMyLocationButtonEnabled
(
true
);
googleMap
.
setOnMapClickListener
(
new
GoogleMap
.
OnMapClickListener
()
{
@Override
public
void
onMapClick
(
LatLng
latLng
)
{
double
latitude
=
latLng
.
latitude
;
double
longitude
=
latLng
.
longitude
;
String
message
=
"Latitude : "
+
latitude
+
"\nLongitude : "
+
longitude
;
Toast
.
makeText
(
requireContext
(),
message
,
Toast
.
LENGTH_SHORT
).
show
();
}
});
googleMap
.
setOnMapLongClickListener
(
new
GoogleMap
.
OnMapLongClickListener
()
{
@Override
public
void
onMapLongClick
(
LatLng
latLng
)
{
double
latitude
=
latLng
.
latitude
;
double
longitude
=
latLng
.
longitude
;
String
title
=
"Lat: "
+
latitude
+
", Lng: "
+
longitude
;
// Crée le marker
MarkerOptions
markerOptions
=
new
MarkerOptions
()
.
position
(
latLng
)
.
title
(
title
);
// Ajoute le marker à la carte
googleMap
.
addMarker
(
markerOptions
);
markerPositions
.
add
(
latLng
);
// Affiche un toast
Toast
.
makeText
(
requireContext
(),
"Marqueur ajouté à "
+
title
,
Toast
.
LENGTH_SHORT
).
show
();
}
});
}
catch
(
SecurityException
e
)
{
}
catch
(
SecurityException
e
)
{
Log
.
e
(
"MapsFragment"
,
"Error while enabling location"
,
e
);
Log
.
e
(
"MapsFragment"
,
"Error while enabling location"
,
e
);
}
}
...
@@ -82,6 +124,12 @@ public class MapsFragment extends Fragment {
...
@@ -82,6 +124,12 @@ public class MapsFragment extends Fragment {
public
View
onCreateView
(
@NonNull
LayoutInflater
inflater
,
public
View
onCreateView
(
@NonNull
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
@Nullable
Bundle
savedInstanceState
)
{
if
(
savedInstanceState
!=
null
)
{
ArrayList
<
LatLng
>
savedMarkers
=
savedInstanceState
.
getParcelableArrayList
(
"markers"
);
if
(
savedMarkers
!=
null
)
{
markerPositions
.
addAll
(
savedMarkers
);
}
}
return
inflater
.
inflate
(
R
.
layout
.
fragment_maps
,
container
,
false
);
return
inflater
.
inflate
(
R
.
layout
.
fragment_maps
,
container
,
false
);
}
}
...
@@ -94,13 +142,13 @@ public class MapsFragment extends Fragment {
...
@@ -94,13 +142,13 @@ public class MapsFragment extends Fragment {
toolbar
.
setOnMenuItemClickListener
(
item
->
{
toolbar
.
setOnMenuItemClickListener
(
item
->
{
if
(
item
.
getItemId
()
==
R
.
id
.
MapTypeNormalAction
)
{
if
(
item
.
getItemId
()
==
R
.
id
.
MapTypeNormalAction
)
{
shareAction
(
);
mMap
.
setMapType
(
GoogleMap
.
MAP_TYPE_NORMAL
);
return
true
;
return
true
;
}
else
if
(
item
.
getItemId
()
==
R
.
id
.
MapTypeHybridAction
)
{
}
else
if
(
item
.
getItemId
()
==
R
.
id
.
MapTypeHybridAction
)
{
openWikipedia
(
);
mMap
.
setMapType
(
GoogleMap
.
MAP_TYPE_HYBRID
);
return
true
;
return
true
;
}
else
if
(
item
.
getItemId
()
==
R
.
id
.
MapTypeSatelliteAction
)
{
}
else
if
(
item
.
getItemId
()
==
R
.
id
.
MapTypeSatelliteAction
)
{
resetAllFields
(
);
mMap
.
setMapType
(
GoogleMap
.
MAP_TYPE_SATELLITE
);
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
@@ -112,4 +160,10 @@ public class MapsFragment extends Fragment {
...
@@ -112,4 +160,10 @@ public class MapsFragment extends Fragment {
mapFragment
.
getMapAsync
(
callback
);
mapFragment
.
getMapAsync
(
callback
);
}
}
}
}
@Override
public
void
onSaveInstanceState
(
@NonNull
Bundle
outState
)
{
super
.
onSaveInstanceState
(
outState
);
outState
.
putParcelableArrayList
(
"markers"
,
markerPositions
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment