From 7ada6b73b53d53e610944e552af396bf0c6f2c20 Mon Sep 17 00:00:00 2001 From: joemacd Date: Fri, 30 Aug 2024 17:55:25 -0400 Subject: [PATCH] New Map Subletting stuff for sublessee tab --- PennMobile/src/main/AndroidManifest.xml | 3 + .../pennmobile/SublesseeDetailsFragment.kt | 21 +- .../pennmobile/SublesseeDetailsMapFragment.kt | 187 ++++++++++++++++++ .../res/layout/fragment_sublessee_details.xml | 14 ++ .../layout/fragment_sublessee_details_map.xml | 37 ++++ 5 files changed, 255 insertions(+), 7 deletions(-) create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/SublesseeDetailsMapFragment.kt create mode 100644 PennMobile/src/main/res/layout/fragment_sublessee_details_map.xml diff --git a/PennMobile/src/main/AndroidManifest.xml b/PennMobile/src/main/AndroidManifest.xml index 506805b6..623eaf72 100644 --- a/PennMobile/src/main/AndroidManifest.xml +++ b/PennMobile/src/main/AndroidManifest.xml @@ -35,6 +35,9 @@ android:name="preloaded_fonts" android:resource="@array/preloaded_fonts" /> + ?, view: View?, position: Int, id: Long) { + // Retrieve selected LocationInfo object + val selectedLocation = typesOfBuildings[position] + + // Add marker and move camera to selected location + loadBuildingData(selectedLocation) + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + // Do nothing if nothing is selected + } + } + + mapFragment?.getMapAsync(this) + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + override fun onMapReady(googleMap: GoogleMap) { + myMap = googleMap + //address string to lat/long + //place marker + //zoom camera to marker + // Convert address to LatLng + val addressCord = getCoordinates(address) + if (addressCord!=null) { + // Place marker on map + myMap.addMarker(MarkerOptions().position(addressCord).title("Sublet Location")) + + // Zoom camera to marker + myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(addressCord, 16.0f)) + } + } + + fun reset() { + myMap.clear() + val addressCord = getCoordinates(address) + if (addressCord!=null) { + // Place marker on map + myMap.addMarker(MarkerOptions().position(addressCord).title("Sublet Location")) + } + } + + fun getCoordinates(address : String) : LatLng? { + val geocoder = Geocoder(requireContext(), Locale.getDefault()) + val addressList = geocoder.getFromLocationName(address, 1) + if (!addressList.isNullOrEmpty()) { + val location = addressList[0] + return LatLng(location.latitude, location.longitude) + } + else { + val addressListPhilly = geocoder.getFromLocationName(address.plus(" Philadelphia, PA 19104"), 1) + if (!addressListPhilly.isNullOrEmpty()) { + val location = addressListPhilly[0] + return LatLng(location.latitude, location.longitude) + } + return null + } + } + + fun loadBuildingData(locationCategory : String) { + reset() + + + val diningLocations = listOf( + LocationInfo("3800 Locust Walk", "1920 Commons"), + LocationInfo("3465 Sansom Street, English House", "English House"), + LocationInfo("215 S 39th Street, Falk at Penn Hillel", "Falk at Penn Hillel"), + LocationInfo("3333 Walnut Street, Hill House", "Hill House"), + LocationInfo("3335 Woodland Walk, Lauder College House", "Lauder College House"), + LocationInfo("201 S 40th St, Quaker Kitchen", "Quaker Kitchen"), + LocationInfo("220 South 33rd Street", "Accenture Café"), + LocationInfo("201 S 40th St", "Café West"), + LocationInfo("3800 Locust Walk", "Gourmet Grocer"), + LocationInfo("3417 Spruce Street","Houston Hall"), + LocationInfo("3620 Locust Walk", "Joe's Café"), + LocationInfo("3650 Spruce Street", "McClelland Sushi & Market"), + LocationInfo("3730 Walnut Street", "Pret a Manger"), + LocationInfo("3800 Locust Walk", "Starbucks") + ) + val libraryLocations = listOf( + LocationInfo("3620 Walnut Street Philadelphia, PA 19104", "Annenberg School Library"), + LocationInfo("3443 Sansom Street Philadelphia, PA 19104", "Biddle Law Library"), + LocationInfo("231 South 34th Street Philadelphia, PA 19104", "Chemistry Library"), + LocationInfo("240 South 40th Street Philadelphia, PA 19104", "Dental Medicine Library"), + LocationInfo("233 South 33rd Street Philadelphia, PA 19104", "Education Commons"), + LocationInfo("220 South 34th Street Philadelphia, PA 19104", "Fisher Fine Arts Library"), + LocationInfo("3610 Hamilton Walk Philadelphia, PA 19104", "Holman Biotech Commons"), + LocationInfo("209 South 33rd Street Philadelphia, PA 19104","Math/Physics/Astronomy LibraryL"), + LocationInfo("3260 South Street Philadelphia, PA 19104", "Museum Library"), + LocationInfo("3420 Walnut Street Philadelphia, PA 19104","Van Pelt") + ) + + val locations = when (locationCategory){ + "Dining" -> diningLocations + "Libraries" -> libraryLocations + else -> null + } + + val icon = when (locationCategory){ + "Dining" -> BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE) + "Libraries" -> BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN) + else -> null + } + + + if (locations != null) { + for (location in locations) { + val tempCoords = getCoordinates(location.address) + if(tempCoords!=null) { + myMap.addMarker(MarkerOptions().position(tempCoords).title(location.name).icon(icon)) + } + } + } + } +} \ No newline at end of file diff --git a/PennMobile/src/main/res/layout/fragment_sublessee_details.xml b/PennMobile/src/main/res/layout/fragment_sublessee_details.xml index 8b07623e..fda40b4a 100644 --- a/PennMobile/src/main/res/layout/fragment_sublessee_details.xml +++ b/PennMobile/src/main/res/layout/fragment_sublessee_details.xml @@ -146,6 +146,20 @@ android:textAllCaps="false" android:textColor="@color/white" app:layout_constraintStart_toEndOf="@id/save_sublet_button" + app:layout_constraintEnd_toEndOf="@+id/map_sublet_button" + app:layout_constraintTop_toBottomOf="@+id/description_text" /> + +