/** * Places a marker on the map for this vehicle, and adds it to our marker HashMap * * @param l Location to add the marker at * @param isRealtime true if the marker shown indicate real-time info, false if it should * indicate schedule * @param status the vehicles status to add to the map * @param response the response which contained the provided status */ private void addMarkerToMap( Location l, boolean isRealtime, ObaTripStatus status, ObaTripsForRouteResponse response) { Marker m = mMap.addMarker( new MarkerOptions() .position(MapHelpV2.makeLatLng(l)) .title(status.getVehicleId()) .icon(getVehicleIcon(isRealtime, status, response))); mVehicleMarkers.put(status.getActiveTripId(), m); mVehicles.put(m, status); }
/** * Removes the stop focus and notify listener * * @param latLng the location on the map where the user tapped if the focus change was triggered * by the user tapping on the map, or null if the focus change was otherwise triggered * programmatically. */ private void removeFocus(LatLng latLng) { if (mMarkerData.getFocus() != null) { mMarkerData.removeFocus(); } // Set map clicked location, if it exists Location location = null; if (latLng != null) { location = MapHelpV2.makeLocation(latLng); } // Notify focus changed every time the map is clicked away from a stop marker mOnFocusChangedListener.onFocusChanged(null, null, location); }
/** * Update an existing marker on the map with the current vehicle status * * @param m Marker to update * @param l Location to add the marker at * @param isRealtime true if the marker shown indicate real-time info, false if it should * indicate schedule * @param status real-time status of the vehicle * @param response response containing the provided status */ private void updateMarker( Marker m, Location l, boolean isRealtime, ObaTripStatus status, ObaTripsForRouteResponse response) { boolean showInfo = m.isInfoWindowShown(); m.setIcon(getVehicleIcon(isRealtime, status, response)); // Update Hashmap with newest status - needed to show info when tapping on marker mVehicles.put(m, status); // Update vehicle position Location markerLoc = MapHelpV2.makeLocation(m.getPosition()); // If its a small distance, animate the movement if (l.distanceTo(markerLoc) < MAX_VEHICLE_ANIMATION_DISTANCE) { AnimationUtil.animateMarkerTo(m, MapHelpV2.makeLatLng(l)); } else { // Just snap the marker to the new location - large animations look weird m.setPosition(MapHelpV2.makeLatLng(l)); } // If the info window was shown, make sure its open (changing the icon could have closed it) if (showInfo) { m.showInfoWindow(); } }
/** * Places a marker on the map for this stop, and adds it to our marker HashMap * * @param stop ObaStop that should be shown on the map * @param routes A list of ObaRoutes that serve this stop */ private void addMarkerToMap(ObaStop stop, List<ObaRoute> routes) { Marker m = mMap.addMarker( new MarkerOptions() .position(MapHelpV2.makeLatLng(stop.getLocation())) .icon(getBitmapDescriptorForBusStopDirection(stop.getDirection())) .flat(true) .anchor( getXPercentOffsetForDirection(stop.getDirection()), getYPercentOffsetForDirection(stop.getDirection()))); mStopMarkers.put(stop.getId(), m); mStops.put(m, stop); for (ObaRoute route : routes) { // ObaRoutes may have already been added for other stops, so check before adding if (!mStopRoutes.containsKey(route.getId())) { mStopRoutes.put(route.getId(), route); } } }