Search in sources :

Example 26 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project androidApp by InspectorIncognito.

the class RouterVectorMapFragment method innerSetRoute.

private void innerSetRoute(Route route) {
    adapter.changeItems(route.steps);
    List<Route> routeList = new ArrayList<>();
    routeList.add(route);
    routerOptionAdapter.changeItems(routeList);
    convertView = routerOptionAdapter.getView(0, convertView, viewGroup);
    title.setText(route.title);
    routerPlugin.changeRoute(route);
    zoomBound(new LatLng(route.northEastPoint.getLatitude(), route.northEastPoint.getLongitude()), new LatLng(route.southWestPoint.getLatitude(), route.southWestPoint.getLongitude()));
}
Also used : ArrayList(java.util.ArrayList) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Route(cl.smartcities.isci.transportinspector.router.route.Route)

Example 27 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project androidApp by InspectorIncognito.

the class RouterVectorMapFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(MapboxMap aMapboxMap) {
            mapboxMap = aMapboxMap;
            mapboxMap.getUiSettings().setCompassMargins(0, 14 * getResources().getDisplayMetrics().heightPixels / 100, 4 * getResources().getDisplayMetrics().widthPixels / 100, 0);
            routerPlugin = new RouterPlugin(mapboxMap, new RedirectionListener(getActivity()));
            if (selectedRoute != null) {
                innerSetRoute(selectedRoute);
                selectedRoute = null;
            }
            locationEngine = new MultiLocationEngine();
            locationPlugin = new UserPlugin(mapView, mapboxMap, locationEngine);
            mapboxMap.addOnScrollListener(new MapboxMap.OnScrollListener() {

                @Override
                public void onScroll() {
                    centerButton.deselectButton();
                    locationPlugin.setTrackingEnabled(false);
                }
            });
            centerButton = new LocationToggleButton((ImageButton) getActivity().findViewById(R.id.floating_button_center), new LocationToggleButton.OnToggleButtonCheck() {

                @Override
                public void onButtonSelected() {
                    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        return;
                    }
                    mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locationEngine.getLastLocation().getLatitude(), locationEngine.getLastLocation().getLongitude()), 16));
                    locationPlugin.setTrackingEnabled(true);
                }

                @Override
                public void onButtonUnselected() {
                    locationPlugin.setTrackingEnabled(false);
                }
            }, false);
            enableLocationPlugin();
            mapView.setVisibility(View.VISIBLE);
        }
    });
}
Also used : RouterPlugin(cl.smartcities.isci.transportinspector.map.plugin.routerPlugin.RouterPlugin) MultiLocationEngine(cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine) UserPlugin(cl.smartcities.isci.transportinspector.map.plugin.userPlugin.UserPlugin) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap)

Example 28 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project androidApp by InspectorIncognito.

the class VectorSearchMapFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(MapboxMap resMapboxMap) {
            mapboxMap = resMapboxMap;
            // mapboxMap.getUiSettings().setCompassImage(ContextCompat.getDrawable(getContext(), R.drawable.direction_arrow));
            mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {

                @Override
                public void onMapClick(@NonNull LatLng point) {
                }
            });
            mapboxMap.getUiSettings().setCompassMargins(0, 14 * getResources().getDisplayMetrics().heightPixels / 100, 4 * getResources().getDisplayMetrics().widthPixels / 100, 0);
            searchPlugin = new SearchPlugin(redirectionListener, service, routeHelper, mapboxMap);
            locationEngine = new MultiLocationEngine();
            locationPlugin = new UserPlugin(mapView, mapboxMap, locationEngine);
            mapboxMap.addOnScrollListener(new MapboxMap.OnScrollListener() {

                @Override
                public void onScroll() {
                    centerButton.deselectButton();
                    locationPlugin.setTrackingEnabled(false);
                }
            });
            centerButton = new LocationToggleButton((ImageButton) getActivity().findViewById(R.id.floating_button_center), new LocationToggleButton.OnToggleButtonCheck() {

                @Override
                public void onButtonSelected() {
                    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        return;
                    }
                    mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locationEngine.getLastLocation().getLatitude(), locationEngine.getLastLocation().getLongitude()), 16));
                    locationPlugin.setTrackingEnabled(true);
                }

                @Override
                public void onButtonUnselected() {
                    locationPlugin.setTrackingEnabled(false);
                }
            }, false);
            enableLocationPlugin();
            Location lastLocation = locationEngine.getLastLocation();
            zoomBound(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()));
        }
    });
}
Also used : MultiLocationEngine(cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine) OnMapReadyCallback(com.mapbox.mapboxsdk.maps.OnMapReadyCallback) SearchPlugin(cl.smartcities.isci.transportinspector.map.plugin.searchPlugin.SearchPlugin) NonNull(android.support.annotation.NonNull) UserPlugin(cl.smartcities.isci.transportinspector.map.plugin.userPlugin.UserPlugin) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap) Location(android.location.Location)

Example 29 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-navigation-android by mapbox.

the class Utils method getRandomLatLng.

public static LatLng getRandomLatLng(double[] bbox) {
    Random random = new Random();
    double randomLat = bbox[1] + (bbox[3] - bbox[1]) * random.nextDouble();
    double randomLon = bbox[0] + (bbox[2] - bbox[0]) * random.nextDouble();
    LatLng latLng = new LatLng(randomLat, randomLon);
    Timber.d("getRandomLatLng: %s", latLng.toString());
    return latLng;
}
Also used : Random(java.util.Random) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 30 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-navigation-android by mapbox.

the class RerouteActivity method userOffRoute.

@Override
public void userOffRoute(Location location) {
    Point newOrigin = Point.fromLngLat(location.getLongitude(), location.getLatitude());
    getRoute(newOrigin, destination, location.getBearing());
    Snackbar.make(contentLayout, "User Off Route", Snackbar.LENGTH_SHORT).show();
    mapboxMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())));
}
Also used : MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Aggregations

LatLng (com.mapbox.mapboxsdk.geometry.LatLng)56 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)12 ArrayList (java.util.ArrayList)10 Point (com.mapbox.geojson.Point)7 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)6 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