Java Code Examples for com.google.android.gms.maps.model.PolylineOptions#color()

The following examples show how to use com.google.android.gms.maps.model.PolylineOptions#color() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DistanceAction.java    From Companion-For-PUBG-Android with MIT License 6 votes vote down vote up
/**
 * If an origin and destination exist this will draw a line between them and
 * render the time it takes to reach the {@link DistanceAction#destination}
 */
private void addPolyline() {
    if (this.origin == null || this.destination == null) {
        return;
    }
    releasePolyline();
    this.destination.marker.setTitle(getTitleForDistance(getDistance()));
    this.destination.marker.setSnippet(this.snippet);
    this.destination.marker.showInfoWindow();
    final PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.add(this.origin.latLng);
    polylineOptions.add(this.destination.latLng);
    polylineOptions.width(5);
    polylineOptions.color(this.colorAccent);
    polylineOptions.zIndex(1000);
    this.polyline = this.mapController.addPolyline(polylineOptions);
}
 
Example 2
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Add a list of Polylines to the map
 *
 * @param map       google map
 * @param polylines multi polyline options
 * @return multi polyline
 */
public static MultiPolyline addPolylinesToMap(GoogleMap map,
                                              MultiPolylineOptions polylines) {
    MultiPolyline multiPolyline = new MultiPolyline();
    for (PolylineOptions polylineOption : polylines.getPolylineOptions()) {
        if (polylines.getOptions() != null) {
            polylineOption.color(polylines.getOptions().getColor());
            polylineOption.geodesic(polylines.getOptions().isGeodesic());
            polylineOption.visible(polylines.getOptions().isVisible());
            polylineOption.zIndex(polylines.getOptions().getZIndex());
            polylineOption.width(polylines.getOptions().getWidth());
        }
        Polyline polyline = addPolylineToMap(map, polylineOption);
        multiPolyline.add(polyline);
    }
    return multiPolyline;
}
 
Example 3
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Add a Polyline to the map as markers
 *
 * @param map                   google map
 * @param polylineOptions       polyline options
 * @param polylineMarkerOptions polyline marker options
 * @param globalPolylineOptions global polyline options
 * @return polyline markers
 */
public PolylineMarkers addPolylineToMapAsMarkers(GoogleMap map,
                                                 PolylineOptions polylineOptions,
                                                 MarkerOptions polylineMarkerOptions,
                                                 PolylineOptions globalPolylineOptions) {

    PolylineMarkers polylineMarkers = new PolylineMarkers(this);

    if (globalPolylineOptions != null) {
        polylineOptions.color(globalPolylineOptions.getColor());
        polylineOptions.geodesic(globalPolylineOptions.isGeodesic());
        polylineOptions.visible(globalPolylineOptions.isVisible());
        polylineOptions.zIndex(globalPolylineOptions.getZIndex());
        polylineOptions.width(globalPolylineOptions.getWidth());
    }

    Polyline polyline = addPolylineToMap(map, polylineOptions);
    polylineMarkers.setPolyline(polyline);

    List<Marker> markers = addPointsToMapAsMarkers(map,
            polylineOptions.getPoints(), polylineMarkerOptions, false);
    polylineMarkers.setMarkers(markers);

    return polylineMarkers;
}
 
Example 4
Source File: DriverMapActivity.java    From UberClone with MIT License 6 votes vote down vote up
@Override
public void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex) {
    if(polylines.size()>0) {
        for (Polyline poly : polylines) {
            poly.remove();
        }
    }

    polylines = new ArrayList<>();
    //add route(s) to the map.
    for (int i = 0; i <route.size(); i++) {

        //In case of more than 5 alternative routes
        int colorIndex = i % COLORS.length;

        PolylineOptions polyOptions = new PolylineOptions();
        polyOptions.color(getResources().getColor(COLORS[colorIndex]));
        polyOptions.width(10 + i * 3);
        polyOptions.addAll(route.get(i).getPoints());
        Polyline polyline = mMap.addPolyline(polyOptions);
        polylines.add(polyline);

        Toast.makeText(getApplicationContext(),"Route "+ (i+1) +": distance - "+ route.get(i).getDistanceValue()+": duration - "+ route.get(i).getDurationValue(),Toast.LENGTH_SHORT).show();
    }

}
 
Example 5
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 6 votes vote down vote up
private Polyline drawPath(List<LatLong> latLongs, int color, float zIndex, Polyline polyline) {
    if (googleMap != null && latLongs != null && !latLongs.isEmpty()) {
        PolylineOptions polyLineOptions = new PolylineOptions();
        polyLineOptions.width(getResources().getDimension(R.dimen._2dp));
        polyLineOptions.color(color);
        polyLineOptions.zIndex(zIndex);

        for (LatLong latLong : latLongs) {
            polyLineOptions.add(new LatLng(latLong.latitude(), latLong.longitude()));
        }

        if (polyline != null) polyline.remove();
        return googleMap.addPolyline(polyLineOptions);
    }

    return null;
}
 
Example 6
Source File: NearbyLocationActivity.java    From FaceT with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onRoutingSuccess(ArrayList<Route> route, int j) {
    if (polylines.size() > 0) {
        for (Polyline poly : polylines) {
            poly.remove();
        }
    }

    polylines = new ArrayList<>();
    //add route(s) to the map.
    for (int i = 0; i < route.size(); i++) {

        //In case of more than 5 alternative routes
        int colorIndex = i % COLORS.length;

        PolylineOptions polyOptions = new PolylineOptions();
        polyOptions.color(getResources().getColor(COLORS[colorIndex]));
        polyOptions.width(10 + i * 3);
        polyOptions.addAll(route.get(i).getPoints());
        Polyline polyline = mMap.addPolyline(polyOptions);
        polylines.add(polyline);
    }
}
 
Example 7
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
private void drawSegmentPathUser(LatLng latLng) {
    PolylineOptions polyLineOptions = new PolylineOptions();
    polyLineOptions.width(getResources().getDimension(R.dimen._2dp));
    polyLineOptions.color(ContextCompat.getColor(getContext(), R.color.blue));
    polyLineOptions.zIndex(2f);

    if (polylineUserLastPath != null) {
        for (LatLng latLngOld : polylineUserLastPath.getPoints())
            polyLineOptions.add(latLngOld);
    }

    polyLineOptions.add(latLng);
    polylineUserLastPath = removePath(polylineUserLastPath);
    polylineUserLastPath = googleMap.addPolyline(polyLineOptions);
}
 
Example 8
Source File: KmlStyle.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new PolylineOption from given properties of an existing PolylineOption
 *
 * @param originalPolylineOption An existing PolylineOption instance
 * @return A new PolylineOption
 */
private static PolylineOptions createPolylineOptions(PolylineOptions originalPolylineOption) {
    PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.color(originalPolylineOption.getColor());
    polylineOptions.width(originalPolylineOption.getWidth());
    polylineOptions.clickable(originalPolylineOption.isClickable());
    return polylineOptions;
}
 
Example 9
Source File: GeoJsonLineStringStyle.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a new PolylineOptions object containing styles for the GeoJsonLineString
 *
 * @return new PolylineOptions object
 */
public PolylineOptions toPolylineOptions() {
    PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.color(mPolylineOptions.getColor());
    polylineOptions.clickable(mPolylineOptions.isClickable());
    polylineOptions.geodesic(mPolylineOptions.isGeodesic());
    polylineOptions.visible(mPolylineOptions.isVisible());
    polylineOptions.width(mPolylineOptions.getWidth());
    polylineOptions.zIndex(mPolylineOptions.getZIndex());
    polylineOptions.pattern(getPattern());
    return polylineOptions;
}
 
Example 10
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the inline linestring style by copying over the styles that have been set
 *
 * @param polylineOptions polygon options object to add inline styles to
 * @param inlineStyle     inline styles to apply
 */
private void setInlineLineStringStyle(PolylineOptions polylineOptions, KmlStyle inlineStyle) {
    PolylineOptions inlinePolylineOptions = inlineStyle.getPolylineOptions();
    if (inlineStyle.isStyleSet("outlineColor")) {
        polylineOptions.color(inlinePolylineOptions.getColor());
    }
    if (inlineStyle.isStyleSet("width")) {
        polylineOptions.width(inlinePolylineOptions.getWidth());
    }
    if (inlineStyle.isLineRandomColorMode()) {
        polylineOptions.color(KmlStyle.computeRandomColor(inlinePolylineOptions.getColor()));
    }
}
 
Example 11
Source File: ShapeActivity.java    From Complete-Google-Map-API-Tutorial with Apache License 2.0 5 votes vote down vote up
private void addPolyline()
{
	googleMap.clear();
	PolylineOptions polylineOptions = new PolylineOptions();
	polylineOptions.add(new LatLng(37.35, -122.0));
	polylineOptions.add(new LatLng(37.45, -122.0));
	polylineOptions.add(new LatLng(37.45, -122.2));
	polylineOptions.add(new LatLng(37.35, -122.2));
	polylineOptions.clickable(true);
	polylineOptions.color(Color.CYAN);

	googleMap.addPolyline(polylineOptions).setTag(new CustomTag("polyline"));
	googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(37.35, -122.0)));
}
 
Example 12
Source File: MainActivity.java    From android-app with GNU General Public License v2.0 4 votes vote down vote up
protected void drawItineraryPolyline(Itinerary itinerary) {
    List<Spot> spots = itinerary.getSpots();
    if (spots != null && !spots.isEmpty()) {

        List<Spot> spotsGoing = new ArrayList<Spot>();
        List<Spot> spotsReturning = new ArrayList<Spot>();
        PolylineOptions line = new PolylineOptions();
        PolylineOptions lineReturning = new PolylineOptions();
        for(int i=0; i<spots.size(); i++) {
            Spot spot = spots.get(i);
            if(spot.getReturning().equalsIgnoreCase("true")){
                spotsReturning.add(spot);
                lineReturning.add(new LatLng(spot.getLatitude(),spot.getLongitude()));
            }
            else{
                spotsGoing.add(spot);
                line.add(new LatLng(spot.getLatitude(),spot.getLongitude()));
            }
        }

        Random rnd = new Random();
        float[] hsv = new float[3];
        map.setInfoWindowAdapter(new BusInfoWindowAdapter(this));
        MapMarker marker = new MapMarker(map);

        int r = rnd.nextInt(256); int g = rnd.nextInt(256); int b = rnd.nextInt(256);
        int color = Color.argb(255, r, g, b);
        lineReturning.color(color);
        lineReturning.width(6);
        lineReturning.geodesic(true);
        map.addPolyline(lineReturning);

        if(!spotsReturning.isEmpty()){
            Color.RGBToHSV(r, g, b, hsv);
            marker.addMarkers(spotsReturning.get(0), hsv[0], itinerary);
            marker.addMarkers(spotsReturning.get(spotsReturning.size() - 1), hsv[0], itinerary);
        }

        r *= 0.75; g *= 0.75; b *= 0.75;
        color = Color.argb(255, r, g, b);
        line.color(color);
        line.width(6);
        line.geodesic(true);
        map.addPolyline(line);

        Color.RGBToHSV(r, g, b, hsv);
        marker.addMarkers(spotsGoing.get(0), hsv[0], itinerary);
        marker.addMarkers(spotsGoing.get(spotsGoing.size() - 1), hsv[0], itinerary);
    }
}
 
Example 13
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
/**
 * Adds a single geometry object to the map with its specified style (used for KML)
 *
 * @param geometry defines the type of object to add to the map
 * @param style    defines styling properties to add to the object when added to the map
 * @return the object that was added to the map, this is a Marker, Polyline, Polygon or an array
 * of either objects
 */
protected Object addKmlPlacemarkToMap(KmlPlacemark placemark, Geometry geometry, KmlStyle style,
                                      KmlStyle inlineStyle, boolean isVisible) {
    String geometryType = geometry.getGeometryType();
    boolean hasDrawOrder = placemark.hasProperty("drawOrder");
    float drawOrder = 0;

    if (hasDrawOrder) {
        try {
            drawOrder = Float.parseFloat(placemark.getProperty("drawOrder"));
        } catch (NumberFormatException e) {
            hasDrawOrder = false;
        }
    }
    switch (geometryType) {
        case "Point":
            MarkerOptions markerOptions = style.getMarkerOptions();
            if (inlineStyle != null) {
                setInlinePointStyle(markerOptions, inlineStyle, style);
            } else if (style.getIconUrl() != null) {
                // Use shared style
                addMarkerIcons(style.getIconUrl(), style.getIconScale(), markerOptions);
            }
            Marker marker = addPointToMap(markerOptions, (KmlPoint) geometry);
            marker.setVisible(isVisible);
            setMarkerInfoWindow(style, marker, placemark);
            if (hasDrawOrder) {
                marker.setZIndex(drawOrder);
            }
            return marker;
        case "LineString":
            PolylineOptions polylineOptions = style.getPolylineOptions();
            if (inlineStyle != null) {
                setInlineLineStringStyle(polylineOptions, inlineStyle);
            } else if (style.isLineRandomColorMode()) {
                polylineOptions.color(KmlStyle.computeRandomColor(polylineOptions.getColor()));
            }
            Polyline polyline = addLineStringToMap(polylineOptions, (LineString) geometry);
            polyline.setVisible(isVisible);
            if (hasDrawOrder) {
                polyline.setZIndex(drawOrder);
            }
            return polyline;
        case "Polygon":
            PolygonOptions polygonOptions = style.getPolygonOptions();
            if (inlineStyle != null) {
                setInlinePolygonStyle(polygonOptions, inlineStyle);
            } else if (style.isPolyRandomColorMode()) {
                polygonOptions.fillColor(KmlStyle.computeRandomColor(polygonOptions.getFillColor()));
            }
            Polygon polygon = addPolygonToMap(polygonOptions, (DataPolygon) geometry);
            polygon.setVisible(isVisible);
            if (hasDrawOrder) {
                polygon.setZIndex(drawOrder);
            }
            return polygon;
        case "MultiGeometry":
            return addMultiGeometryToMap(placemark, (KmlMultiGeometry) geometry, style, inlineStyle,
                    isVisible);
    }
    return null;
}
 
Example 14
Source File: HistorySingleActivity.java    From UberClone with MIT License 4 votes vote down vote up
@Override
public void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex) {

    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    builder.include(pickupLatLng);
    builder.include(destinationLatLng);
    LatLngBounds bounds = builder.build();

    int width = getResources().getDisplayMetrics().widthPixels;
    int padding = (int) (width*0.2);

    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);

    mMap.animateCamera(cameraUpdate);

    mMap.addMarker(new MarkerOptions().position(pickupLatLng).title("pickup location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pickup)));
    mMap.addMarker(new MarkerOptions().position(destinationLatLng).title("destination"));

    if(polylines.size()>0) {
        for (Polyline poly : polylines) {
            poly.remove();
        }
    }

    polylines = new ArrayList<>();
    //add route(s) to the map.
    for (int i = 0; i <route.size(); i++) {

        //In case of more than 5 alternative routes
        int colorIndex = i % COLORS.length;

        PolylineOptions polyOptions = new PolylineOptions();
        polyOptions.color(getResources().getColor(COLORS[colorIndex]));
        polyOptions.width(10 + i * 3);
        polyOptions.addAll(route.get(i).getPoints());
        Polyline polyline = mMap.addPolyline(polyOptions);
        polylines.add(polyline);

        Toast.makeText(getApplicationContext(),"Route "+ (i+1) +": distance - "+ route.get(i).getDistanceValue()+": duration - "+ route.get(i).getDurationValue(),Toast.LENGTH_SHORT).show();
    }

}
 
Example 15
Source File: NiboOriginDestinationPickerFragment.java    From Nibo with MIT License 4 votes vote down vote up
private void drawPolyline(final List<Route> routes) {

        ArrayList<LatLng> points = null;
        PolylineOptions lineOptions = new PolylineOptions();

        mCoordinatorlayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mOriginEditText.clearFocus();
                mDestinationEditText.clearFocus();
                mCoordinatorlayout.requestLayout();
            }
        }, 1000);

        for (int i = 0; i < routes.size(); i++) {
            this.mListLatLng.addAll(routes.get(i).points);
        }

        lineOptions.width(10);
        if (mPrimaryPolyLineColor == 0) {
            lineOptions.color(Color.BLACK);
        } else {
            lineOptions.color(ContextCompat.getColor(getContext(), mPrimaryPolyLineColor));
        }
        lineOptions.startCap(new SquareCap());
        lineOptions.endCap(new SquareCap());
        lineOptions.jointType(ROUND);
        mPrimaryPolyLine = mMap.addPolyline(lineOptions);

        PolylineOptions greyOptions = new PolylineOptions();
        greyOptions.width(10);
        if (mSecondaryPolyLineColor == 0) {
            greyOptions.color(Color.GRAY);
        } else {
            lineOptions.color(ContextCompat.getColor(getContext(), mSecondaryPolyLineColor));
        }
        greyOptions.startCap(new SquareCap());
        greyOptions.endCap(new SquareCap());
        greyOptions.jointType(ROUND);
        mSecondaryPolyLine = mMap.addPolyline(greyOptions);

        animatePolyLine();
    }
 
Example 16
Source File: MainActivity.java    From NYU-BusTracker-Android with Apache License 2.0 4 votes vote down vote up
private void updateMapWithNewStartOrEnd() {
    setUpMapIfNeeded();
    mMap.clear();
    if (startStop == null || endStop == null) return;

    List<Route> routesBetweenStartAndEnd = startStop.getRoutesTo(endStop);
    clickableMapMarkers = new HashMap<>();
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    boolean validBuilder = false;
    for (Route r : routesBetweenStartAndEnd) {
        if (!r.getSegments().isEmpty()) {
            if (BuildConfig.DEBUG)
                Log.v(REFACTOR_LOG_TAG, "Updating map with route: " + r.getLongName());
            for (Stop s : r.getStops()) {
                for (Stop f : s.getFamily()) {
                    if ((!f.isHidden() && !f.isRelatedTo(startStop) && !f.isRelatedTo(endStop)) || (f == startStop || f == endStop)) {
                        // Only put one representative from a family of stops on the p
                        Marker mMarker = mMap.addMarker(new MarkerOptions().position(f.getLocation()).title(f.getName())
                                .anchor(0.5f, 0.5f).icon(BitmapDescriptorFactory.fromBitmap(
                                        BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_map_stop))));
                        clickableMapMarkers.put(mMarker.getId(), true);
                    }
                }
            }
            // Adds the segments of every Route to the map.
            for (PolylineOptions p : r.getSegments()) {
                if (p != null) {
                    for (LatLng loc : p.getPoints()) {
                        validBuilder = true;
                        builder.include(loc);
                    }
                    p.color(getResources().getColor(R.color.main_buttons));
                    mMap.addPolyline(p);
                }
            }
        }
    }
    if (validBuilder) {
        LatLngBounds bounds = builder.build();
        try {
            mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 30));
        } catch (IllegalStateException e) {      // In case the view is not done being created.
            //e.printStackTrace();
            mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, this.getResources().getDisplayMetrics().widthPixels, this.getResources().getDisplayMetrics().heightPixels, 100));
        }
    }
}
 
Example 17
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Set the polyline options
 *
 * @param style           shape style
 * @param polylineOptions polyline options
 * @param visible         visible flag
 */
private void setPolylineOptions(ObservationShapeStyle style, PolylineOptions polylineOptions, boolean visible) {
    polylineOptions.width(style.getStrokeWidth());
    polylineOptions.color(style.getStrokeColor());
    polylineOptions.visible(visible);
    polylineOptions.geodesic(MapShapeObservation.GEODESIC);
}
 
Example 18
Source File: StyleUtils.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Set the style into the polyline options
 *
 * @param polylineOptions polyline options
 * @param style           style row
 * @param density         display density: {@link android.util.DisplayMetrics#density}
 * @return true if style was set into the polyline options
 */
public static boolean setStyle(PolylineOptions polylineOptions, StyleRow style, float density) {

    if (style != null) {

        Color color = style.getColorOrDefault();
        polylineOptions.color(color.getColorWithAlpha());

        double width = style.getWidthOrDefault();
        polylineOptions.width((float) width * density);

    }

    return style != null;
}