Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected void onCreate(Bundle savedInstanceState) {

// Check for location permission
permissionsManager = new PermissionsManager(this);
if (!permissionsManager.areLocationPermissionsGranted(this)) {
if (!PermissionsManager.areLocationPermissionsGranted(this)) {
recyclerView.setEnabled(false);
permissionsManager.requestLocationPermissions(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.mapbox.services.Constants;
import com.mapbox.services.android.testapp.R;
import com.mapbox.services.android.testapp.Utils;
import com.mapbox.services.api.ServicesException;
import com.mapbox.services.api.directions.v5.DirectionsCriteria;
import com.mapbox.services.api.directions.v5.MapboxDirections;
import com.mapbox.services.api.directions.v5.models.DirectionsResponse;
Expand Down Expand Up @@ -91,16 +90,13 @@ public void onMapReady(MapboxMap mapboxMapReady) {
.snippet("San Jose"));

// Get route from API
try {
getRoute(origin, destination);
} catch (ServicesException servicesException) {
servicesException.printStackTrace();
}
getRoute(origin, destination);

}
});
}

private void getRoute(Position origin, Position destination) throws ServicesException {
private void getRoute(Position origin, Position destination) {
ArrayList<Position> positions = new ArrayList<>();
positions.add(origin);
positions.add(destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.mapbox.services.api.directions.v5.models.LegStep;
import com.mapbox.services.api.directions.v5.models.RouteLeg;
import com.mapbox.services.api.navigation.v5.RouteUtils;
import com.mapbox.services.api.utils.turf.TurfException;
import com.mapbox.services.commons.models.Position;
import com.mapbox.services.commons.utils.PolylineUtils;

Expand Down Expand Up @@ -94,15 +93,7 @@ public void onMapClick(@NonNull LatLng point) {
} else if (to == null) {
setTo(point);
} else {
try {
doUtils(point);
} catch (ServicesException servicesException) {
Log.e(LOG_TAG, "Services exception: " + servicesException.getMessage());
servicesException.printStackTrace();
} catch (TurfException turfException) {
Log.e(LOG_TAG, "Turf exception: " + turfException.getMessage());
turfException.printStackTrace();
}
doUtils(point);
}
}
});
Expand All @@ -121,16 +112,11 @@ private void setTo(LatLng point) {
.position(point)
.title("To"));

try {
getRoute(Position.fromCoordinates(from.getLongitude(), from.getLatitude()),
Position.fromCoordinates(to.getLongitude(), to.getLatitude()));
} catch (ServicesException servicesException) {
showMessage(servicesException.getMessage());
servicesException.printStackTrace();
}
getRoute(Position.fromCoordinates(from.getLongitude(), from.getLatitude()),
Position.fromCoordinates(to.getLongitude(), to.getLatitude()));
}

private void doUtils(LatLng point) throws ServicesException, TurfException {
private void doUtils(LatLng point) {
// Remove previous
if (userTap != null) {
mapboxMap.removeMarker(userTap);
Expand Down Expand Up @@ -159,7 +145,7 @@ private void doUtils(LatLng point) throws ServicesException, TurfException {
// Draw snap to route lines
snapLines = new ArrayList<>();
for (int stepIndex = 0; stepIndex < route.getSteps().size(); stepIndex++) {
Position snapPoint = routeUtils.getSnapToRoute(position, route, stepIndex);
Position snapPoint = RouteUtils.getSnapToRoute(position, route, stepIndex);
LatLng[] points = new LatLng[] {
point,
new LatLng(snapPoint.getLatitude(), snapPoint.getLongitude())};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
Expand Down Expand Up @@ -209,12 +208,11 @@ private void updateLayers() {

for (int i = 0; i < restaurants.size(); i++) {

try {
if (mapboxMap.getLayer(restaurants.get(i).getStringProperty("name" + "-layer")) != null) {
mapboxMap.removeLayer(restaurants.get(i).getStringProperty("name") + "-layer");
} catch (NoSuchLayerException exception) {
// Layer hasn't been added yet. No worries :)
}


SymbolLayer marker = new SymbolLayer(
restaurants.get(i).getStringProperty("name") + "-layer",
restaurants.get(i).getStringProperty("name") + "-source"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.services.android.testapp.R;
import com.mapbox.services.android.testapp.Utils;
import com.mapbox.services.api.ServicesException;
import com.mapbox.services.api.geocoding.v5.GeocodingCriteria;
import com.mapbox.services.api.geocoding.v5.MapboxGeocoding;
import com.mapbox.services.api.geocoding.v5.models.CarmenFeature;
Expand Down Expand Up @@ -56,11 +55,7 @@ public void onMapClick(@NonNull LatLng point) {
mapboxMap.addMarker(new MarkerOptions()
.position(point)
.title("Your finger is here"));
try {
geocode(point);
} catch (ServicesException servicesException) {
setMessage("Geocoding failed: " + servicesException.getMessage());
}
geocode(point);
}
});
}
Expand Down Expand Up @@ -113,7 +108,7 @@ public void onLowMemory() {
* Forward geocoding
*/

private void geocode(LatLng point) throws ServicesException {
private void geocode(LatLng point) {
Position position = Position.fromCoordinates(point.getLongitude(), point.getLatitude());
MapboxGeocoding client = new MapboxGeocoding.Builder()
.setAccessToken(Utils.getMapboxAccessToken(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.mapbox.services.api.directions.v5.models.DirectionsResponse;
import com.mapbox.services.api.directions.v5.models.DirectionsRoute;
import com.mapbox.services.api.navigation.v5.RouteUtils;
import com.mapbox.services.api.utils.turf.TurfException;
import com.mapbox.services.api.utils.turf.TurfMeasurement;
import com.mapbox.services.commons.geojson.LineString;
import com.mapbox.services.commons.models.Position;
Expand Down Expand Up @@ -102,19 +101,12 @@ public void onMapClick(@NonNull LatLng point) {

destination = Position.fromCoordinates(point.getLongitude(), point.getLatitude());

try {
getRoute(
Position.fromCoordinates(car.getPosition().getLongitude(), car.getPosition().getLatitude()),
Position.fromCoordinates(point.getLongitude(), point.getLatitude())
);
} catch (ServicesException servicesException) {
servicesException.printStackTrace();
Log.e(TAG, "onMapReady: " + servicesException.getMessage());
}

getRoute(
Position.fromCoordinates(car.getPosition().getLongitude(), car.getPosition().getLatitude()),
Position.fromCoordinates(point.getLongitude(), point.getLatitude())
);
}
});

} // End onMapReady
});
} // End onCreate
Expand Down Expand Up @@ -281,7 +273,7 @@ private void drawRoute(DirectionsRoute route) {
}
}

private void checkIfOffRoute() throws ServicesException, TurfException {
private void checkIfOffRoute() {

Position carCurrentPosition = Position.fromCoordinates(
car.getPosition().getLongitude(),
Expand Down Expand Up @@ -344,12 +336,7 @@ public void run() {
// Check that the vehicles off route or not. If you aren't simulating the car,
// and want to use this example in the real world, the checkingIfOffRoute method
// should go in a locationListener.
try {
checkIfOffRoute();
} catch (ServicesException | TurfException exception) {
exception.printStackTrace();
Log.e(TAG, "check if off route error: " + exception.getMessage());
}
checkIfOffRoute();

// Keeping the current point count we are on.
count++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.services.Constants;
import com.mapbox.services.android.testapp.R;
import com.mapbox.services.api.ServicesException;
import com.mapbox.services.api.directions.v5.DirectionsCriteria;
import com.mapbox.services.api.directions.v5.MapboxDirections;
import com.mapbox.services.api.directions.v5.models.DirectionsResponse;
import com.mapbox.services.api.directions.v5.models.DirectionsRoute;
import com.mapbox.services.api.navigation.v5.RouteUtils;
import com.mapbox.services.api.utils.turf.TurfException;
import com.mapbox.services.api.utils.turf.TurfMisc;
import com.mapbox.services.commons.geojson.LineString;
import com.mapbox.services.commons.geojson.Point;
Expand Down Expand Up @@ -120,19 +118,11 @@ public void onMapClick(@NonNull LatLng point) {
.position(point)
);

RouteUtils routeUtils = new RouteUtils();
Position snappedPosition = null;

try {
snappedPosition = routeUtils.getSnapToRoute(
Position.fromCoordinates(point.getLongitude(), point.getLatitude()),
currentRoute.getLegs().get(0),
stepCount
);
} catch (ServicesException | TurfException exception) {
exception.printStackTrace();
Log.e(TAG, "snap to route util: " + exception.getMessage());
}
Position snappedPosition = RouteUtils.getSnapToRoute(
Position.fromCoordinates(point.getLongitude(), point.getLatitude()),
currentRoute.getLegs().get(0),
stepCount
);

if (snappedPosition == null) {
Log.i(TAG, "snapPosition is null");
Expand All @@ -155,39 +145,31 @@ public void onMapClick(@NonNull LatLng point) {
mapboxMap.removePolyline(distancePolyline);
}

try {
LineString slicedLine = TurfMisc.lineSlice(
Point.fromCoordinates(snappedPosition),
Point.fromCoordinates(coords.get(coords.size() - 1)),
LineString.fromCoordinates(coords)
);

List<Position> linePositions = slicedLine.getCoordinates();
List<LatLng> lineLatLng = new ArrayList<>();
for (Position pos : linePositions) {
lineLatLng.add(new LatLng(pos.getLatitude(), pos.getLongitude()));
}
LineString slicedLine = TurfMisc.lineSlice(
Point.fromCoordinates(snappedPosition),
Point.fromCoordinates(coords.get(coords.size() - 1)),
LineString.fromCoordinates(coords)
);

distancePolyline = mapboxMap.addPolyline(new PolylineOptions()
.addAll(lineLatLng)
.color(Color.parseColor("#f1f075"))
.width(5f)
);
} catch (TurfException turfException) {
turfException.printStackTrace();
List<Position> linePositions = slicedLine.getCoordinates();
List<LatLng> lineLatLng = new ArrayList<>();
for (Position pos : linePositions) {
lineLatLng.add(new LatLng(pos.getLatitude(), pos.getLongitude()));
}

distancePolyline = mapboxMap.addPolyline(new PolylineOptions()
.addAll(lineLatLng)
.color(Color.parseColor("#f1f075"))
.width(5f)
);
}

@Override
public void onMapReady(MapboxMap mapboxMap) {
SnapToRouteActivity.this.mapboxMap = mapboxMap;
mapboxMap.setOnMapClickListener(this);

try {
getRoute(origin, destination);
} catch (ServicesException servicesException) {
servicesException.printStackTrace();
}
getRoute(origin, destination);
}

private void drawDistanceRoutePolyline(Position snappedPosition) {
Expand All @@ -199,30 +181,26 @@ private void drawDistanceRoutePolyline(Position snappedPosition) {
mapboxMap.removePolyline(distanceRoutePolyline);
}

try {
LineString slicedRouteLine = TurfMisc.lineSlice(
Point.fromCoordinates(snappedPosition),
Point.fromCoordinates(routeCoords.get(routeCoords.size() - 1)),
LineString.fromCoordinates(routeCoords)
);

List<Position> linePositions = slicedRouteLine.getCoordinates();
List<LatLng> lineLatLng = new ArrayList<>();
for (Position pos : linePositions) {
lineLatLng.add(new LatLng(pos.getLatitude(), pos.getLongitude()));
}
LineString slicedRouteLine = TurfMisc.lineSlice(
Point.fromCoordinates(snappedPosition),
Point.fromCoordinates(routeCoords.get(routeCoords.size() - 1)),
LineString.fromCoordinates(routeCoords)
);

distanceRoutePolyline = mapboxMap.addPolyline(new PolylineOptions()
.addAll(lineLatLng)
.color(Color.parseColor("#3887be"))
.width(5f)
);
} catch (TurfException turfException) {
turfException.printStackTrace();
List<Position> linePositions = slicedRouteLine.getCoordinates();
List<LatLng> lineLatLng = new ArrayList<>();
for (Position pos : linePositions) {
lineLatLng.add(new LatLng(pos.getLatitude(), pos.getLongitude()));
}

distanceRoutePolyline = mapboxMap.addPolyline(new PolylineOptions()
.addAll(lineLatLng)
.color(Color.parseColor("#3887be"))
.width(5f)
);
}

private void getRoute(Position origin, Position destination) throws ServicesException {
private void getRoute(Position origin, Position destination) {

MapboxDirections client = new MapboxDirections.Builder()
.setOrigin(origin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.mapbox.services.Constants;
import com.mapbox.services.android.testapp.R;
import com.mapbox.services.android.testapp.Utils;
import com.mapbox.services.api.ServicesException;
import com.mapbox.services.api.staticimage.v1.MapboxStaticImage;

public class StaticImageActivity extends AppCompatActivity {

private static final String LOG_TAG = "StaticImageActivity";

// All default Mapbox styles
public static final String[] MAPBOX_STYLES = {
Constants.MAPBOX_STYLE_STREETS, Constants.MAPBOX_STYLE_LIGHT,
Expand Down Expand Up @@ -66,22 +62,16 @@ private String[] buildDataset() {
int i = 0;
for (double[] place : PLACES) {
for (String style : MAPBOX_STYLES) {
String imageUrl = null;
try {
imageUrl = getImageUrl(style, place, isRetina);
dataset[i] = imageUrl;
i++;
} catch (ServicesException servicesException) {
Log.e(LOG_TAG, "Error: " + servicesException.getMessage());
servicesException.printStackTrace();
}
String imageUrl = getImageUrl(style, place, isRetina);
dataset[i] = imageUrl;
i++;
}
}

return dataset;
}

private String getImageUrl(String style, double[] place, boolean isRetina) throws ServicesException {
private String getImageUrl(String style, double[] place, boolean isRetina) {
MapboxStaticImage staticImage = new MapboxStaticImage.Builder()
.setAccessToken(Utils.getMapboxAccessToken(this))
.setUsername(Constants.MAPBOX_USER)
Expand Down
Loading