use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.
the class LocationLayerAnimator method feedNewLocation.
void feedNewLocation(@NonNull Location newLocation, @NonNull CameraPosition currentCameraPosition, boolean isGpsNorth) {
if (previousLocation == null) {
previousLocation = newLocation;
locationUpdateTimestamp = SystemClock.elapsedRealtime();
}
if (invalidUpdateInterval()) {
return;
}
LatLng previousLayerLatLng = getPreviousLayerLatLng();
float previousLayerBearing = getPreviousLayerGpsBearing();
LatLng previousCameraLatLng = currentCameraPosition.target;
float previousCameraBearing = (float) currentCameraPosition.bearing;
LatLng targetLatLng = new LatLng(newLocation);
float targetLayerBearing = newLocation.getBearing();
float targetCameraBearing = newLocation.getBearing();
targetCameraBearing = checkGpsNorth(isGpsNorth, targetCameraBearing);
updateLayerAnimators(previousLayerLatLng, targetLatLng, previousLayerBearing, targetLayerBearing);
updateCameraAnimators(previousCameraLatLng, previousCameraBearing, targetLatLng, targetCameraBearing);
playAllLocationAnimators(getAnimationDuration());
previousLocation = newLocation;
}
use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.
the class RegionSelectionFragment method createRegion.
OfflineTilePyramidRegionDefinition createRegion() {
if (mapboxMap == null) {
throw new NullPointerException("MapboxMap is null and can't be used to create Offline region" + "definition.");
}
RectF rectF = getSelectionRegion();
LatLng northEast = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.right, rectF.top));
LatLng southWest = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.left, rectF.bottom));
LatLngBounds bounds = new LatLngBounds.Builder().include(northEast).include(southWest).build();
double cameraZoom = mapboxMap.getCameraPosition().zoom;
float pixelRatio = getActivity().getResources().getDisplayMetrics().density;
return new OfflineTilePyramidRegionDefinition(mapboxMap.getStyleUrl(), bounds, cameraZoom - 2, cameraZoom + 2, pixelRatio);
}
use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.
the class GeoJsonPlugin method parseGeoJsonString.
/**
* @param geoJson String of the GeoJSON file
* @return DataModel list of polylines, polygons, and point with bounded
*/
private DataModel parseGeoJsonString(String geoJson) {
int pointCount = 0;
DataModel dataModel = new DataModel();
LatLngBounds.Builder builder = new LatLngBounds.Builder();
FeatureCollection featureCollection = FeatureCollection.fromJson(geoJson);
List<Feature> listFeature = featureCollection.features();
for (Feature feature : listFeature) {
String featureType = feature.geometry().type();
if (!TextUtils.isEmpty(featureType)) {
if (featureType.equalsIgnoreCase("LineString")) {
List<LatLng> latLngs = new ArrayList<>();
LineString lineString = (LineString) feature.geometry();
List<Point> coordinates = lineString.coordinates();
for (Point position : coordinates) {
LatLng latLng = new LatLng(position.latitude(), position.longitude());
latLngs.add(latLng);
pointCount++;
builder.include(latLng);
}
PolyData polylinePolyData = new PolyData();
polylinePolyData.setPoints(latLngs);
polylinePolyData.setType(featureType);
dataModel.addPolyline(polylinePolyData);
} else if (featureType.equalsIgnoreCase("Point")) {
Point point = (Point) feature.geometry();
if (point != null) {
LatLng latLng = new LatLng(point.latitude(), point.longitude());
MarkerData markerData = new MarkerData();
markerData.setPoint(latLng);
markerData.setProperties(feature.properties());
dataModel.addMarker(markerData);
pointCount++;
builder.include(latLng);
}
} else if (featureType.equalsIgnoreCase("Polygon")) {
List<LatLng> latLngs = new ArrayList<>();
Polygon polygon = (Polygon) feature.geometry();
List<Point> listPosition = polygon.coordinates().get(0);
for (Point position : listPosition) {
LatLng latLng = new LatLng(position.latitude(), position.longitude());
latLngs.add(latLng);
pointCount++;
builder.include(latLng);
}
PolyData polygonPolyData = new PolyData();
polygonPolyData.setPoints(latLngs);
polygonPolyData.setType(featureType);
dataModel.addPolygon(polygonPolyData);
} else {
// TODO
}
}
}
if (pointCount > 1) {
dataModel.setBounds(builder.build());
}
return dataModel;
}
use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.
the class PlacePickerActivity method makeReverseGeocodingSearch.
private void makeReverseGeocodingSearch() {
LatLng latLng = mapboxMap.getCameraPosition().target;
viewModel.reverseGeocode(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()), accessToken, options);
}
use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-plugins-android by mapbox.
the class GeoJsonActivity method onMapReady.
@Override
public void onMapReady(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
geoJsonPlugin = new GeoJsonPluginBuilder().withContext(this).withMap(mapboxMap).withOnLoadingURL(this).withOnLoadingFileAssets(this).withOnLoadingFilePath(this).withMarkerClickListener(this).withRandomFillColor().build();
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(32.6546, 51.6680), 7));
}
Aggregations