Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Multiple version bump hotfixes #643

Merged
merged 24 commits into from
Mar 6, 2018
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
2 changes: 2 additions & 0 deletions MapboxAndroidDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ dependencies {

// Mapbox dependencies
api (dependenciesList.mapboxMapSdk)
implementation dependenciesList.mapboxTurf
implementation dependenciesList.mapboGeoJson

// Mapbox plugins
implementation dependenciesList.mapboxPluginLocationLayer
Expand Down
6 changes: 3 additions & 3 deletions MapboxAndroidDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
android:label="@string/activity_plugins_places_plugin_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity"/>
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
</activity>
<activity
android:name=".examples.plugins.LocationPluginActivity"
Expand Down Expand Up @@ -504,8 +504,8 @@
</activity>
<activity
android:name=".labs.SymbolLayerMapillaryActivity"
android:screenOrientation="portrait"
android:label="@string/activity_lab_symbol_layer_and_mapillary_on_map_title">
android:label="@string/activity_lab_symbol_layer_and_mapillary_on_map_title"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
import com.mapbox.mapboxandroiddemo.examples.extrusions.PopulationDensityExtrusionActivity;
import com.mapbox.mapboxandroiddemo.examples.extrusions.RotationExtrusionActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.DirectionsActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.MatrixApiActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.MapMatchingActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.MatrixApiActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.OptimizationActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.SimplifyPolylineActivity;
import com.mapbox.mapboxandroiddemo.examples.javaservices.StaticImageActivity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import android.util.Log;
import android.widget.Toast;

import com.mapbox.api.directions.v5.DirectionsCriteria;
import com.mapbox.api.directions.v5.MapboxDirections;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxandroiddemo.R;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
Expand All @@ -14,10 +19,6 @@
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
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.commons.geojson.LineString;
import com.mapbox.services.commons.models.Position;

Expand Down Expand Up @@ -53,10 +54,10 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_javaservices_directions);

// Alhambra landmark in Granada, Spain.
final Position origin = Position.fromCoordinates(-3.588098, 37.176164);
final Point origin = Point.fromLngLat(-3.588098, 37.176164);

// Plaza del Triunfo in Granada, Spain.
final Position destination = Position.fromCoordinates(-3.601845, 37.184080);
final Point destination = Point.fromLngLat(-3.601845, 37.184080);


// Setup the MapView
Expand All @@ -69,11 +70,11 @@ public void onMapReady(MapboxMap mapboxMap) {

// Add origin and destination to the map
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(origin.getLatitude(), origin.getLongitude()))
.position(new LatLng(origin.latitude(), origin.longitude()))
.title(getString(R.string.directions_activity_marker_options_origin_title))
.snippet(getString(R.string.directions_activity_marker_options_origin_snippet)));
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(destination.getLatitude(), destination.getLongitude()))
.position(new LatLng(destination.latitude(), destination.longitude()))
.title(getString(R.string.directions_activity_marker_options_destination_title))
.snippet(getString(R.string.directions_activity_marker_options_destination_snippet)));

Expand All @@ -83,14 +84,14 @@ public void onMapReady(MapboxMap mapboxMap) {
});
}

private void getRoute(Position origin, Position destination) {
private void getRoute(Point origin, Point destination) {

client = new MapboxDirections.Builder()
.setOrigin(origin)
.setDestination(destination)
.setOverview(DirectionsCriteria.OVERVIEW_FULL)
.setProfile(DirectionsCriteria.PROFILE_CYCLING)
.setAccessToken(getString(R.string.access_token))
client = MapboxDirections.builder()
.origin(origin)
.destination(destination)
.overview(DirectionsCriteria.OVERVIEW_FULL)
.profile(DirectionsCriteria.PROFILE_CYCLING)
.accessToken(getString(R.string.access_token))
.build();

client.enqueueCall(new Callback<DirectionsResponse>() {
Expand All @@ -103,16 +104,16 @@ public void onResponse(Call<DirectionsResponse> call, Response<DirectionsRespons
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().getRoutes().size() < 1) {
} else if (response.body().routes().size() < 1) {
Log.e(TAG, "No routes found");
return;
}

// Print some info about the route
currentRoute = response.body().getRoutes().get(0);
Log.d(TAG, "Distance: " + currentRoute.getDistance());
currentRoute = response.body().routes().get(0);
Log.d(TAG, "Distance: " + currentRoute.distance());
Toast.makeText(DirectionsActivity.this, String.format(getString(R.string.directions_activity_toast_message),
currentRoute.getDistance()), Toast.LENGTH_SHORT).show();
currentRoute.distance()), Toast.LENGTH_SHORT).show();

// Draw the route on the map
drawRoute(currentRoute);
Expand All @@ -128,7 +129,7 @@ public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {

private void drawRoute(DirectionsRoute route) {
// Convert LineString coordinates into LatLng[]
LineString lineString = LineString.fromPolyline(route.getGeometry(), PRECISION_6);
LineString lineString = LineString.fromPolyline(route.geometry(), PRECISION_6);
List<Position> coordinates = lineString.getCoordinates();
LatLng[] points = new LatLng[coordinates.size()];
for (int i = 0; i < coordinates.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.mapbox.api.matching.v5.MapboxMapMatching;
import com.mapbox.api.matching.v5.models.MapMatchingResponse;
import com.mapbox.core.exceptions.ServicesException;
import com.mapbox.geojson.Point;
import com.mapbox.geojson.utils.PolylineUtils;
import com.mapbox.mapboxandroiddemo.R;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.Polyline;
Expand All @@ -15,14 +20,9 @@
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.services.Constants;
import com.mapbox.services.api.ServicesException;
import com.mapbox.services.api.mapmatching.v5.MapMatchingCriteria;
import com.mapbox.services.api.mapmatching.v5.MapboxMapMatching;
import com.mapbox.services.api.mapmatching.v5.models.MapMatchingResponse;
import com.mapbox.services.commons.geojson.FeatureCollection;
import com.mapbox.services.commons.geojson.LineString;
import com.mapbox.services.commons.models.Position;
import com.mapbox.services.commons.utils.PolylineUtils;

import java.io.BufferedReader;
import java.io.InputStream;
Expand All @@ -35,6 +35,9 @@
import retrofit2.Callback;
import retrofit2.Response;

import static com.mapbox.api.directions.v5.DirectionsCriteria.PROFILE_DRIVING;


/**
* Match raw GPS points to the map so they align with roads and pathways.
*/
Expand All @@ -57,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.activity_javaservices_map_matching);

mapView = (MapView) findViewById(R.id.mapView);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
Expand Down Expand Up @@ -110,11 +113,11 @@ protected void onSaveInstanceState(Bundle outState) {
mapView.onSaveInstanceState(outState);
}

private class DrawGeoJson extends AsyncTask<Void, Void, List<Position>> {
private class DrawGeoJson extends AsyncTask<Void, Void, List<Point>> {
@Override
protected List<Position> doInBackground(Void... voids) {
protected List<Point> doInBackground(Void... voids) {

List<Position> points = new ArrayList<>();
List<Point> points = new ArrayList<>();

try {
// Load GeoJSON file
Expand All @@ -125,54 +128,54 @@ protected List<Position> doInBackground(Void... voids) {
while ((cp = rd.read()) != -1) {
sb.append((char) cp);
}

inputStream.close();
FeatureCollection featureCollection = FeatureCollection.fromJson(sb.toString());
LineString lineString = (LineString) featureCollection.getFeatures().get(0).getGeometry();
points = lineString.getCoordinates();
for (Position singlePosition : lineString.getCoordinates()) {
points.add(Point.fromLngLat(singlePosition.getLongitude(),
singlePosition.getLatitude()));
}
} catch (Exception exception) {
Log.e(TAG, "Exception Loading GeoJSON: " + exception.toString());
}

return points;
}

@Override
protected void onPostExecute(List<Position> points) {
protected void onPostExecute(List<Point> points) {
super.onPostExecute(points);
drawBeforeMapMatching(points);

Position[] coordinates = new Position[points.size()];
drawMapMatched(points.toArray(coordinates));
drawMapMatched(points);
}
}

private void drawBeforeMapMatching(List<Position> points) {
private void drawBeforeMapMatching(List<Point> points) {
LatLng[] pointsArray = new LatLng[points.size()];
for (int i = 0; i < points.size(); i++) {
pointsArray[i] = new LatLng(points.get(i).getLatitude(), points.get(i).getLongitude());
pointsArray[i] = new LatLng(points.get(i).latitude(), points.get(i).longitude());
}

map.addPolyline(new PolylineOptions()
.add(pointsArray)
.color(Color.parseColor("#8a8acb"))
.alpha(0.65f)
.width(4));
.add(pointsArray)
.color(Color.parseColor("#8a8acb"))
.alpha(0.65f)
.width(4));
}

private void drawMapMatched(Position[] coordinates) {
private void drawMapMatched(List<Point> coordinates) {
try {
// Setup the request using a client.
MapboxMapMatching client = new MapboxMapMatching.Builder()
.setAccessToken(Mapbox.getAccessToken())
.setProfile(MapMatchingCriteria.PROFILE_DRIVING)
.setCoordinates(coordinates)
.build();
MapboxMapMatching client = MapboxMapMatching.builder()
.accessToken(Mapbox.getAccessToken())
.profile(PROFILE_DRIVING)
.coordinates(coordinates)
.build();

// Execute the API call and handle the response.
client.enqueueCall(new Callback<MapMatchingResponse>() {
@Override
public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingResponse> response) {
public void onResponse(Call<MapMatchingResponse> call,
Response<MapMatchingResponse> response) {
// Create a new list to store the map matched coordinates.
List<LatLng> mapMatchedPoints = new ArrayList<>();

Expand All @@ -181,16 +184,15 @@ public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingRespo
// Convert the map matched response list from position to latlng coordinates.
// By default, the SDK uses MapMatchingCriteria.GEOMETRY_POLYLINE_6, therefore
// you need Constants.PRECISION_6 for the decode to be right
String geometry = response.body().getMatchings().get(0).getGeometry();
List<Position> positions = PolylineUtils.decode(geometry, Constants.PRECISION_6);
if (positions == null) {
String geometry = response.body().matchings().get(0).geometry();
List<Point> pointList = PolylineUtils.decode(geometry, Constants.PRECISION_6);
if (pointList == null) {
return;
}

for (int i = 0; i < positions.size(); i++) {
mapMatchedPoints.add(new LatLng(
positions.get(i).getLatitude(),
positions.get(i).getLongitude()));
for (Point singlePosition : pointList) {
mapMatchedPoints.add(new LatLng(singlePosition.latitude(),
singlePosition.longitude()));
}

if (mapMatchedRoute != null) {
Expand All @@ -199,9 +201,9 @@ public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingRespo

// Add the map matched route to the Mapbox map.
mapMatchedRoute = map.addPolyline(new PolylineOptions()
.addAll(mapMatchedPoints)
.color(Color.parseColor("#3bb2d0"))
.width(4));
.addAll(mapMatchedPoints)
.color(Color.parseColor("#3bb2d0"))
.width(4));
} else {
// If the response code does not response "OK" an error has occurred.
Log.e(TAG, "Too many coordinates, profile not found, invalid input, or no match.");
Expand Down
Loading