Class MapFragment
- All Implemented Interfaces:
ComponentCallbacks
,View.OnCreateContextMenuListener
,ActivityResultCaller
,HasDefaultViewModelProviderFactory
,LifecycleOwner
,ViewModelStoreOwner
,androidx.savedstate.SavedStateRegistryOwner
,OrientationDetector.Listener
,MapView.DirectionsEventListener
,MapView.MapClickEventListener
,MapView.MapEventListener
,MapView.MarkerEventListener
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class androidx.fragment.app.Fragment
Fragment.InstantiationException, Fragment.SavedState
-
Field Summary
Fields inherited from class androidx.fragment.app.Fragment
mPreviousWho
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
End directions to the given placemark.Gets a copy of the currentDirectionsOptions
, defaulting to theMapView
options if none are set on this fragment or the default ones if aMapView
was not initialized yet.Gets a copy of the currentMapOptions
, defaulting to theMapView
options if none are set on this fragment or the default ones if aMapView
was not initialized yet.Gets our ownedMapView
if created, otherwise null.markerForPlacemark
(Placemark placemark) This method is an opportunity to supply your ownMarker
instance for a given Placemark.markerForSelectedMarker
(Marker markerToSelect) void
onActivityResult
(int requestCode, int resultCode, Intent data) boolean
onCalloutClick
(Marker marker) Called when the callout is tapped.void
onCreateView
(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) void
boolean
onDirectionsClick
(Marker marker) Called when the directions action of the marker callout view is tapped.boolean
Called when the user exits directions.boolean
Called when there has been an error getting directions.void
Called when the directions need to reroute.boolean
Called when the directions are calculated.boolean
Called when the user clicks the Location button.void
onLocationUpdated
(MeridianLocation location) Called when the Location has updated for this map.boolean
onLongPress
(float x, float y) Called when the user long presses on the map.boolean
Called when the user clicks on the map, but not on a control or Marker.void
Called when there has been an error retrieving the map from the internet or parsing the map that was retrieved.void
Called after loading of the map image is complete.void
Called when initial loading of a map starts, this is called before any web request or graphics related loading happens.void
Called after the map and Placemarks have been loaded and rendered.void
onMapTransformChange
(Matrix transform) Called when screen to map transform for this map changes.boolean
onMarkerDeselect
(Marker marker) Called when a user taps somewhere on the map deselecting a marker.boolean
onMarkerSelect
(Marker marker) Called when a user taps a Marker on the map.void
void
onOrientationUpdated
(MeridianOrientation orientation) Called when orientation of the device has been updated.void
boolean
Called when the user clicks the Overview button.void
onPause()
void
Called after loading Placemarks.void
onResume()
boolean
onRouteStepIndexChange
(int index) Called when the route step has been updated.void
onSaveInstanceState
(Bundle outState) protected void
onSourceResult
(DirectionsDestination destination, DirectionsSource source) This event takes place right before directions are retrieved from the server and provide an opportunity to change the source and destination, or just be notified of the event.void
onStop()
void
Called when the accessibility option has been toggled by the user.void
Set the DirectionsEventListener for this MapFragment.void
setDirectionsOptions
(DirectionsOptions options) Set current directions options.void
Set the MapClickEventListener for this MapFragment.void
setMapEventListener
(MapView.MapEventListener listener) Set the MapEventListener for this MapFragment.void
setMapOptions
(MapOptions options) Set current map options.void
Set the MarkerEventListener for this MapFragment.void
startDirections
(DirectionsDestination destination) Start directions to the given placemark.Methods inherited from class androidx.fragment.app.Fragment
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getDefaultViewModelCreationExtras, getDefaultViewModelProviderFactory, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getParentFragmentManager, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onDestroyOptionsMenu, onDestroyView, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onStart, onViewCreated, onViewStateRestored, postponeEnterTransition, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
-
Constructor Details
-
MapFragment
public MapFragment()
-
-
Method Details
-
getMapOptions
Gets a copy of the currentMapOptions
, defaulting to theMapView
options if none are set on this fragment or the default ones if aMapView
was not initialized yet.Changing the properties of the returned
MapOptions
will have no effect. To change theMapOptions
for this MapFragment, call setMapOptions. -
setMapOptions
Set current map options.These will be applied to our owned
MapView
instance either immediately if it exists, or automatically when created. -
getDirectionsOptions
Gets a copy of the currentDirectionsOptions
, defaulting to theMapView
options if none are set on this fragment or the default ones if aMapView
was not initialized yet.Changing the properties of the returned
DirectionsOptions
will have no effect. To change theDirectionsOptions
for this MapFragment, call setDirectionsOptions. -
setDirectionsOptions
Set current directions options.These will be applied to our owned
MapView
instance either immediately if it exists, or automatically when created. -
getMapView
Gets our ownedMapView
if created, otherwise null.You may call methods and set properties on the returned view.
-
setMarkerEventListener
Set the MarkerEventListener for this MapFragment. -
setDirectionsEventListener
Set the DirectionsEventListener for this MapFragment. -
setMapEventListener
Set the MapEventListener for this MapFragment. -
setMapClickEventListener
Set the MapClickEventListener for this MapFragment. -
onCreate
-
onSaveInstanceState
- Overrides:
onSaveInstanceState
in classFragment
-
onCreateView
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) - Overrides:
onCreateView
in classFragment
-
onResume
public void onResume() -
onPause
public void onPause() -
onStop
public void onStop() -
onDestroy
public void onDestroy() -
startDirections
Start directions to the given placemark. -
endDirections
public void endDirections()End directions to the given placemark. -
onActivityResult
- Overrides:
onActivityResult
in classFragment
-
onSourceResult
This event takes place right before directions are retrieved from the server and provide an opportunity to change the source and destination, or just be notified of the event.Make sure to call super or the directions request will be canceled.
-
onMarkerSelect
Description copied from interface:MapView.MarkerEventListener
Called when a user taps a Marker on the map.- Specified by:
onMarkerSelect
in interfaceMapView.MarkerEventListener
- Parameters:
marker
- An instance of the marker that was tapped.- Returns:
true
to indicate that the event has been handled,false
to allow the default action to take place.
-
onMarkerDeselect
Description copied from interface:MapView.MarkerEventListener
Called when a user taps somewhere on the map deselecting a marker.- Specified by:
onMarkerDeselect
in interfaceMapView.MarkerEventListener
- Parameters:
marker
- An instance of the marker that was previously selected.- Returns:
true
to indicate that the event has been handled,false
to allow the default action to take place.
-
markerForPlacemark
Description copied from interface:MapView.MarkerEventListener
This method is an opportunity to supply your ownMarker
instance for a given Placemark.You can use this to completely customize the look of Placemarks on the map. The default implementation returns null.
- Specified by:
markerForPlacemark
in interfaceMapView.MarkerEventListener
- Parameters:
placemark
- The Placemark that is requesting aMarker
for displaying on the map.- Returns:
- A new instance of a
Marker
subclass or null to request that MapView create a defaultMarker
.
-
markerForSelectedMarker
Description copied from interface:MapView.MarkerEventListener
This method is an opportunity to supply your own selectedMarker
instance for a selectedMarker
.You can use this to completely customize the look of selected Placemarks on the map. The default implementation returns null.
- Specified by:
markerForSelectedMarker
in interfaceMapView.MarkerEventListener
- Parameters:
markerToSelect
- The Marker that is being selected.- Returns:
- A new instance of a
Marker
subclass or null to request that MapView create a defaultMarker
.
-
onCalloutClick
Description copied from interface:MapView.MarkerEventListener
Called when the callout is tapped.The callout is the screen footer which lists the marker name and has a directions button.
- Specified by:
onCalloutClick
in interfaceMapView.MarkerEventListener
- Parameters:
marker
- An instance of the marker that was active when the callout was tapped.- Returns:
true
to indicate that the event has been handled,false
to allow the default action to take place.
-
onMapLoadStart
public void onMapLoadStart()Description copied from interface:MapView.MapEventListener
Called when initial loading of a map starts, this is called before any web request or graphics related loading happens.- Specified by:
onMapLoadStart
in interfaceMapView.MapEventListener
-
onMapLoadFinish
public void onMapLoadFinish()Description copied from interface:MapView.MapEventListener
Called after loading of the map image is complete.It has not been rendered at this point.
- Specified by:
onMapLoadFinish
in interfaceMapView.MapEventListener
-
onPlacemarksLoadFinish
public void onPlacemarksLoadFinish()Description copied from interface:MapView.MapEventListener
Called after loading Placemarks.This is a good place to add your own markers and edit data in the loaded Placemarks before they are rendered to the screen.
- Specified by:
onPlacemarksLoadFinish
in interfaceMapView.MapEventListener
-
onMapRenderFinish
public void onMapRenderFinish()Description copied from interface:MapView.MapEventListener
Called after the map and Placemarks have been loaded and rendered.Changing any markers should be avoided.
- Specified by:
onMapRenderFinish
in interfaceMapView.MapEventListener
-
onMapLoadFail
Description copied from interface:MapView.MapEventListener
Called when there has been an error retrieving the map from the internet or parsing the map that was retrieved.- Specified by:
onMapLoadFail
in interfaceMapView.MapEventListener
- Parameters:
tr
- Exception that occurred while loading map.
-
onMapTransformChange
Description copied from interface:MapView.MapEventListener
Called when screen to map transform for this map changes.- Specified by:
onMapTransformChange
in interfaceMapView.MapEventListener
- Parameters:
transform
- new transform matrix.
-
onLocationUpdated
Description copied from interface:MapView.MapEventListener
Called when the Location has updated for this map.- Specified by:
onLocationUpdated
in interfaceMapView.MapEventListener
- Parameters:
location
- The updated location.
-
onOrientationUpdated
Description copied from interface:MapView.MapEventListener
Called when orientation of the device has been updated.- Specified by:
onOrientationUpdated
in interfaceMapView.MapEventListener
- Parameters:
orientation
- The updated orientation.
-
onLocationButtonClick
public boolean onLocationButtonClick()Description copied from interface:MapView.MapClickEventListener
Called when the user clicks the Location button.- Specified by:
onLocationButtonClick
in interfaceMapView.MapClickEventListener
- Returns:
- true if the event has been handled, false if we still want the default behavior to occur.
-
onOverviewButtonClick
public boolean onOverviewButtonClick()Description copied from interface:MapView.MapClickEventListener
Called when the user clicks the Overview button.Note that the overview button is in the upper left corner of the map and only appears if there is a map without a building that is the default map. This is not associated with the overview button in directions.
- Specified by:
onOverviewButtonClick
in interfaceMapView.MapClickEventListener
- Returns:
- true if the event has been handled, false if we still want the default behavior to occur.
-
onMapClick
public boolean onMapClick()Description copied from interface:MapView.MapClickEventListener
Called when the user clicks on the map, but not on a control or Marker.In most cases this should be an indicator that the user is trying to dismiss the active UI.
- Specified by:
onMapClick
in interfaceMapView.MapClickEventListener
- Returns:
- true if the event has been handled, false if we still want the default behavior to occur.
-
onLongPress
public boolean onLongPress(float x, float y) Description copied from interface:MapView.MapClickEventListener
Called when the user long presses on the map.- Specified by:
onLongPress
in interfaceMapView.MapClickEventListener
- Returns:
- true if the event has been handled, false if we still want the default behavior to occur.
-
onDirectionsReroute
public void onDirectionsReroute()Description copied from interface:MapView.DirectionsEventListener
Called when the directions need to reroute.- Specified by:
onDirectionsReroute
in interfaceMapView.DirectionsEventListener
-
onDirectionsClick
Description copied from interface:MapView.DirectionsEventListener
Called when the directions action of the marker callout view is tapped.- Specified by:
onDirectionsClick
in interfaceMapView.DirectionsEventListener
- Parameters:
marker
- An instance of the marker that was active when the callout was tapped.- Returns:
true
to indicate that the event has been handled,false
to allow the default action to take place.
-
onDirectionsStart
public boolean onDirectionsStart()Description copied from interface:MapView.DirectionsEventListener
Called when the directions are calculated.- Specified by:
onDirectionsStart
in interfaceMapView.DirectionsEventListener
- Returns:
true
to indicate that the event has been handled,false
to allow the default action to take place.
-
onRouteStepIndexChange
public boolean onRouteStepIndexChange(int index) Description copied from interface:MapView.DirectionsEventListener
Called when the route step has been updated.- Specified by:
onRouteStepIndexChange
in interfaceMapView.DirectionsEventListener
- Parameters:
index
- The index of the updated step.- Returns:
true
to indicate that the event has been handled,false
to allow the default action to take place.
-
onDirectionsClosed
public boolean onDirectionsClosed()Description copied from interface:MapView.DirectionsEventListener
Called when the user exits directions.- Specified by:
onDirectionsClosed
in interfaceMapView.DirectionsEventListener
- Returns:
true
to indicate that the event has been handled,false
to allow the default action to take place.
-
onDirectionsError
Description copied from interface:MapView.DirectionsEventListener
Called when there has been an error getting directions.- Specified by:
onDirectionsError
in interfaceMapView.DirectionsEventListener
- Parameters:
tr
- Exception that occurred while loading directions.- Returns:
true
to indicate that the event has been handled,false
to allow the default action to take place.
-
onUseAccessiblePathsChange
public void onUseAccessiblePathsChange()Description copied from interface:MapView.DirectionsEventListener
Called when the accessibility option has been toggled by the user.- Specified by:
onUseAccessiblePathsChange
in interfaceMapView.DirectionsEventListener
-
onOrientationRight
public void onOrientationRight()- Specified by:
onOrientationRight
in interfaceOrientationDetector.Listener
-
onOrientationWrong
public void onOrientationWrong()- Specified by:
onOrientationWrong
in interfaceOrientationDetector.Listener
-