diff --git a/app/src/main/java/com/mhacks/android/ui/MainActivity.java b/app/src/main/java/com/mhacks/android/ui/MainActivity.java index b9d17c9e..a94b23cc 100644 --- a/app/src/main/java/com/mhacks/android/ui/MainActivity.java +++ b/app/src/main/java/com/mhacks/android/ui/MainActivity.java @@ -84,6 +84,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); // Add the toolbar diff --git a/app/src/main/java/com/mhacks/android/ui/map/GroundOverlayLoader.java b/app/src/main/java/com/mhacks/android/ui/map/GroundOverlayLoader.java index 9639a28f..8f83d7a6 100644 --- a/app/src/main/java/com/mhacks/android/ui/map/GroundOverlayLoader.java +++ b/app/src/main/java/com/mhacks/android/ui/map/GroundOverlayLoader.java @@ -38,7 +38,7 @@ protected Object doInBackground(Object... args){ bMapOptions.inSampleSize = 4; options = new GroundOverlayOptions() .image(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(activity - .getResources(), R.drawable.map_no_edges, bMapOptions))) + .getResources(), R.drawable.grand_map, bMapOptions))) .positionFromBounds(bounds); return null; } diff --git a/app/src/main/java/com/mhacks/android/ui/map/MapViewFragment.java b/app/src/main/java/com/mhacks/android/ui/map/MapViewFragment.java index 908c5a88..e41abb6a 100644 --- a/app/src/main/java/com/mhacks/android/ui/map/MapViewFragment.java +++ b/app/src/main/java/com/mhacks/android/ui/map/MapViewFragment.java @@ -19,6 +19,7 @@ import com.google.android.gms.maps.model.GroundOverlayOptions; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; +import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.mhacks.android.data.model.Location; @@ -36,6 +37,7 @@ public class MapViewFragment extends Fragment implements AdapterView.OnItemSelec public static final String TAG = "MapViewFragment"; public static final String MAP_PIN = "mapPin"; + private ArrayList mMarkers = new ArrayList<>(); //Views private View mMapFragView; @@ -47,7 +49,6 @@ public class MapViewFragment extends Fragment implements AdapterView.OnItemSelec @Nullable private GroundOverlayOptions option = null; -// NetworkManager networkManager = NetworkManager.getInstance(); private static final LatLng NORTHEAST = new LatLng(42.29353, -83.713641); private static final LatLng SOUTHWEST = new LatLng(42.29182, -83.716611); private static final LatLngBounds CORNERS = new LatLngBounds(SOUTHWEST, NORTHEAST); @@ -95,15 +96,21 @@ public void run() { else{ if(gMap != null){ ArrayList _locations = LocationsQueue.locations; + float zoom = (float) 16.0; if(!_locations.isEmpty()){ - gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(42.2919466, -83.7153427), 16)); + double swLat = 42.287503; + double swLong = -83.718795; for (int i = 0; i < _locations.size(); i++){ - gMap.addMarker(new MarkerOptions().position(new LatLng(_locations.get(i).getLatitude(), + if(_locations.get(i).getLatitude() < swLat || _locations.get(i).getLongitude() < swLong) zoom = (float) 13.25; + Marker _marker = gMap.addMarker(new MarkerOptions().position(new LatLng(_locations.get(i).getLatitude(), _locations.get(i).getLongitude())).title(_locations.get(i).getName())); + mMarkers.add(_marker); } + _locations.clear(); } - } + gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(42.2919466, -83.7153427), zoom)); + } else{ Log.e(TAG, "Map was not loaded"); } @@ -113,6 +120,10 @@ public void run() { @Override public void onDestroyView() { + for(Marker _marker: mMarkers){ + _marker.remove(); + } + mMarkers.clear(); super.onDestroyView(); } @@ -136,13 +147,20 @@ public void onMapReady(GoogleMap map){ mapLock.unlock(); ArrayList _locations = LocationsQueue.locations; + float zoom = (float) 16.0; if(!_locations.isEmpty()){ + double swLat = 42.287503; + double swLong = -83.718795; for (int i = 0; i < _locations.size(); i++){ - gMap.addMarker(new MarkerOptions().position(new LatLng(_locations.get(i).getLatitude(), + if(_locations.get(i).getLatitude() < swLat || _locations.get(i).getLongitude() < swLong) zoom = (float) 13.25; + Marker _marker = gMap.addMarker(new MarkerOptions().position(new LatLng(_locations.get(i).getLatitude(), _locations.get(i).getLongitude())).title(_locations.get(i).getName())); + mMarkers.add(_marker); } + _locations.clear(); } + gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(42.2919466, -83.7153427), zoom)); gMap.getUiSettings().setMyLocationButtonEnabled(true); //TODO: stop it from complaining about disabled permissions diff --git a/app/src/main/res/drawable/grand_map.png b/app/src/main/res/drawable/grand_map.png new file mode 100644 index 00000000..2249b27e Binary files /dev/null and b/app/src/main/res/drawable/grand_map.png differ