Skip to content

Commit

Permalink
minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dangiashish committed Feb 17, 2023
1 parent 901c053 commit 733bb40
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
23 changes: 12 additions & 11 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.codebyashish.googledirectionapi;

public class KeyConstants {
public class Constants {

public static String DIRECTION_BASE_URL = "https://maps.googleapis.com/maps/api/directions/json?";
public static String START_LOCATION = "start_location";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private RouteDrawing(Builder builder) {
}

protected String constructURL() {
StringBuilder stringBuilder = new StringBuilder(KeyConstants.DIRECTION_BASE_URL);
StringBuilder stringBuilder = new StringBuilder(Constants.DIRECTION_BASE_URL);
LatLng origin = this.waypoints.get(0);
stringBuilder.append("origin=");
stringBuilder.append(origin.latitude);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ArrayList<RouteInfoModel> parse() throws ErrorHandling {
} else {
try {
JSONObject json = new JSONObject(result);
if (!json.getString("status").equals(KeyConstants.OK)) {
if (!json.getString("status").equals(Constants.OK)) {
throw new ErrorHandling(json);
} else {
JSONArray jsonRoutes = json.getJSONArray("routes");
Expand All @@ -46,7 +46,7 @@ public ArrayList<RouteInfoModel> parse() throws ErrorHandling {
JSONObject leg = jsonRoute.getJSONArray("legs").getJSONObject(0);
JSONArray steps = leg.getJSONArray("steps");

routeInfoModel.setName(leg.getString(KeyConstants.START_ADDRESS) + " to " + leg.getString(KeyConstants.END_ADDRESS));
routeInfoModel.setName(leg.getString(Constants.START_ADDRESS) + " to " + leg.getString(Constants.END_ADDRESS));
routeInfoModel.setCopyright(jsonRoute.getString("copyrights"));
routeInfoModel.setDurationText(leg.getJSONObject("duration").getString("text"));
routeInfoModel.setDurationValue(leg.getJSONObject("duration").getInt("value"));
Expand All @@ -60,7 +60,7 @@ public ArrayList<RouteInfoModel> parse() throws ErrorHandling {

for(int y = 0; y < steps.length(); ++y) {
JSONObject step = steps.getJSONObject(y);
JSONObject start = step.getJSONObject(KeyConstants.START_LOCATION);
JSONObject start = step.getJSONObject(Constants.START_LOCATION);
LatLng position = new LatLng(start.getDouble("lat"), start.getDouble("lng"));
stepsModel.setPoint(position);
int length = step.getJSONObject("distance").getInt("value");
Expand Down

0 comments on commit 733bb40

Please sign in to comment.