Search in sources :

Example 1 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project apps-android-commons by commons-app.

the class NearbyMapFragment method addCurrentLocationMarker.

/**
     * Adds a marker for the user's current position. Adds a
     * circle which uses the accuracy * 2, to draw a circle
     * which represents the user's position with an accuracy
     * of 95%.
     */
public void addCurrentLocationMarker(MapboxMap mapboxMap) {
    MarkerOptions currentLocationMarker = new MarkerOptions().position(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude()));
    mapboxMap.addMarker(currentLocationMarker);
    List<LatLng> circle = createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(), curLatLng.getAccuracy() * 2, 100);
    mapboxMap.addPolygon(new PolygonOptions().addAll(circle).strokeColor(Color.parseColor("#55000000")).fillColor(Color.parseColor("#11000000")));
}
Also used : MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) PolygonOptions(com.mapbox.mapboxsdk.annotations.PolygonOptions) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 2 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project apps-android-commons by commons-app.

the class NearbyMapFragment method setupMapView.

private void setupMapView(Bundle savedInstanceState) {
    MapboxMapOptions options = new MapboxMapOptions().styleUrl(Style.OUTDOORS).camera(new CameraPosition.Builder().target(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude())).zoom(11).build());
    // create map
    mapView = new MapView(getActivity(), options);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(MapboxMap mapboxMap) {
            mapboxMap.addMarkers(baseMarkerOptions);
            mapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {

                @Override
                public boolean onMarkerClick(@NonNull Marker marker) {
                    if (marker instanceof NearbyMarker) {
                        NearbyMarker nearbyMarker = (NearbyMarker) marker;
                        Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
                        NearbyInfoDialog.showYourself(getActivity(), place);
                    }
                    return false;
                }
            });
            addCurrentLocationMarker(mapboxMap);
        }
    });
    if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("theme", true)) {
        mapView.setStyleUrl(getResources().getString(R.string.map_theme_dark));
    } else {
        mapView.setStyleUrl(getResources().getString(R.string.map_theme_light));
    }
}
Also used : MapboxMapOptions(com.mapbox.mapboxsdk.maps.MapboxMapOptions) GsonBuilder(com.google.gson.GsonBuilder) NonNull(android.support.annotation.NonNull) MapView(com.mapbox.mapboxsdk.maps.MapView) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Marker(com.mapbox.mapboxsdk.annotations.Marker) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 3 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project apps-android-commons by commons-app.

the class NearbyMapFragment method createCircleArray.

/**
     * Creates a series of points that create a circle on the map.
     * Takes the center latitude, center longitude of the circle,
     * the radius in meter and the number of nodes of the circle.
     *
     * @return List List of LatLng points of the circle.
     */
public List<LatLng> createCircleArray(double centerLat, double centerLong, float radius, int nodes) {
    List<LatLng> circle = new ArrayList<>();
    float radiusKilometer = radius / 1000;
    double radiusLong = radiusKilometer / (111.320 * Math.cos(centerLat * Math.PI / 180));
    double radiusLat = radiusKilometer / 110.574;
    for (int i = 0; i < nodes; i++) {
        double theta = ((double) i / (double) nodes) * (2 * Math.PI);
        double nodeLongitude = centerLong + radiusLong * Math.cos(theta);
        double nodeLatitude = centerLat + radiusLat * Math.sin(theta);
        circle.add(new LatLng(nodeLatitude, nodeLongitude));
    }
    return circle;
}
Also used : ArrayList(java.util.ArrayList) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 4 with LatLng

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;
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 5 with LatLng

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);
}
Also used : RectF(android.graphics.RectF) OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition) PointF(android.graphics.PointF) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Aggregations

LatLng (com.mapbox.mapboxsdk.geometry.LatLng)57 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)12 ArrayList (java.util.ArrayList)10 Point (com.mapbox.geojson.Point)7 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)7 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)6 NonNull (android.support.annotation.NonNull)5 PointF (android.graphics.PointF)4 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)4 ValueAnimator (android.animation.ValueAnimator)3 MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)3 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)3 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)3 Poi (io.jawg.osmcontributor.model.entities.Poi)3 Subscribe (org.greenrobot.eventbus.Subscribe)3 Intent (android.content.Intent)2 Location (android.location.Location)2 View (android.view.View)2 RouteHelper (cl.smartcities.isci.transportinspector.database.RouteHelper)2 BusClickHandler (cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)2