Skip to content

MapsFragment

stardustgd edited this page Feb 14, 2023 · 5 revisions

MapsFragment

The MapsFragment class manages the Google Maps API. All the features that need to be added to the map go in this class. Whenever MainActivity executes, it automatically calls getSupportFragmentManager() which loads the code in this class. When this class is instantiated, onCreateView() is called. Once the view has been created, the OnMapReadyCallback callback is performed. The callback handles most of the logic for the map and is where implementations for new features should be written.

onLocationChanged

Updates the fields currentLat and currentLong whenever the user's location is changed.

Parameters:

  • Location location
    • User's current location

Return value:

  • none

onProviderEnabled

onProviderDisabled

enableCircleFilter

enableParkingCalculator

Calculates the nearest parking lot to the user's current location.

This is done by updating the user's current location, checking that the location is valid, calling calculateNearestLot() with the user's location, moving the map camera to the marker's location, and then displaying the marker's information window.

Parameters:

  • none

Return value:

  • true if the user has a valid location
  • false if the user has an invalid location (or if location permissions are denied)

getCurrentLocation

onRequestPermissionsResult

onCreateView

onViewCreated

setMapStyle

Changes the theme of the map.

Parameters:

  • GoogleMap googleMap
    • The current map object

Return value:

  • none

setMapBounds

Sets the map bounds.

Parameters:

  • GoogleMap googleMap
    • The current map object

Return value:

  • none

moveMapCamera

Moves the map camera to a specified location.

Parameters:

  • GoogleMap googleMap
    • The current map object
  • LatLng coords
    • The specified coordinates to move the camera to

Return value:

  • none

parseJson

Parses the file locations.json and creates Marker and MapLocation objects to be used in the map.

Parameters:

  • GoogleMap googleMap
    • The current map object

Return value:

  • none

calculateNearestLot

Calculates the nearest parking lot to the user's marker.

The current implementation of this method still requires a marker object as a parameter, rather than the user's current location.

Parameters:

  • Marker newUserMarker
    • The Marker object that represents the user's current location.

Return value:

  • Pair<Integer, Double>
    • The integer represents the index of the nearest lot to the user (index ranges from 0-17, representing Lot A1 to Lot F2).
    • The double represents the lot with the least distance to the user.

calculateMarkerDistance

popupViewCreator

Used to create a new popup within the MapsFragment. (Deprecated)

Parameters:

  • View popupView
    • The View object of the popup
  • View view
    • The current View

Return value:

  • none

BitmapFromVector

Converts a vector xml or svg file into a BitmapDescriptor. This is used to create and use custom markers in the map.

Parameters:

  • Context context
    • The current application Context
  • int vectorResId
    • The ID number of the vector

Return value:

  • BitmapDescriptor
Clone this wiki locally