diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/io/request/survey/submit/ObaSubmitSurveyRequest.java b/onebusaway-android/src/main/java/org/onebusaway/android/io/request/survey/submit/ObaSubmitSurveyRequest.java index fe4353d38..eb5728997 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/io/request/survey/submit/ObaSubmitSurveyRequest.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/io/request/survey/submit/ObaSubmitSurveyRequest.java @@ -65,6 +65,24 @@ public Builder setSurveyId(int surveyId) { return this; } + public Builder setStopLatitude(double stopLatitude) { + try { + mPostData.appendQueryParameter("stop_latitude", String.valueOf(stopLatitude)); + } catch (Exception e) { + e.printStackTrace(); + } + return this; + } + + public Builder setStopLongitude(double stopLongitude) { + try { + mPostData.appendQueryParameter("stop_longitude", String.valueOf(stopLongitude)); + } catch (Exception e) { + e.printStackTrace(); + } + return this; + } + public Builder setResponses(JSONArray responses) { try { mPostData.appendQueryParameter("responses", responses.toString()); diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/survey/SurveyManager.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/survey/SurveyManager.java index 6ed4f9094..5c1816995 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/survey/SurveyManager.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/survey/SurveyManager.java @@ -259,7 +259,9 @@ private void sendSurveySubmission(String apiUrl, String userIdentifier, int surv ObaSubmitSurveyRequest request = new ObaSubmitSurveyRequest.Builder(context, apiUrl) .setUserIdentifier(userIdentifier) .setSurveyId(surveyId) - .setStopIdentifier(SurveyUtils.getCurrentStopIdentifier(currentStop,isVisibleOnStops)) + .setStopIdentifier(SurveyUtils.getCurrentStopIdentifier(currentStop, isVisibleOnStops)) + .setStopLatitude(SurveyUtils.getCurrentStopLatitude(currentStop, isVisibleOnStops)) + .setStopLongitude(SurveyUtils.getCurrentStopLongitude(currentStop, isVisibleOnStops)) .setResponses(requestBody) .setListener(submitSurveyRequestListener).build(); new Thread(request::call).start(); diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/survey/utils/SurveyUtils.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/survey/utils/SurveyUtils.java index 593b9f2b3..4aa1ecef1 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/survey/utils/SurveyUtils.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/survey/utils/SurveyUtils.java @@ -424,6 +424,7 @@ public static boolean isValidEmbeddedDataList(ArrayList embeddedDataList /** * Converts an array of route IDs to an ArrayList. + * * @param routes An array of route IDs. * @return An ArrayList containing the route IDs from the input array. */ @@ -435,17 +436,37 @@ public static ArrayList getRoutesIDList(String[] routes) { * Returns the stop identifier if the stop is non-null, has a valid ID, * and is marked as visible; otherwise, returns null. * - * @param currentStop The current stop object. - * @param visibleOnStops Indicates if the stop is visible. + * @param currentStop The current stop object. + * @param visibleOnStops Indicates if the stop is visible. * @return The stop identifier or null if conditions are not met. */ public static String getCurrentStopIdentifier(ObaStop currentStop, boolean visibleOnStops) { - return (currentStop != null && currentStop.getId() != null && visibleOnStops) - ? currentStop.getId() - : null; + return (currentStop != null && currentStop.getId() != null && visibleOnStops) ? currentStop.getId() : null; } + /** + * Returns the current stop latitude if the stop is non-null and visible. + * + * @param currentStop The current stop object. + * @param visibleOnStops Indicates if the stop is visible. + * @return The current stop latitude or 0 if the stop is null or not visible. + */ + public static double getCurrentStopLatitude(ObaStop currentStop, boolean visibleOnStops) { + if (currentStop == null || !visibleOnStops) return 0; + return currentStop.getLatitude(); + } + /** + * Returns the current stop longitude if the stop is non-null and visible. + * + * @param currentStop The current stop object. + * @param visibleOnStops Indicates if the stop is visible. + * @return The current stop longitude or 0 if the stop is null or not visible. + */ + public static double getCurrentStopLongitude(ObaStop currentStop, boolean visibleOnStops) { + if (currentStop == null || !visibleOnStops) return 0; + return currentStop.getLongitude(); + } }