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

The following examples show how to use com.google.android.gms.maps.model.PolylineOptions#add() . 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
/**
 * Convert a {@link LineString} to a {@link PolylineOptions}
 *
 * @param lineString line string
 * @return polyline options
 */
public PolylineOptions toPolyline(LineString lineString) {

    PolylineOptions polylineOptions = new PolylineOptions();
    Double z = null;

    // Try to simplify the number of points in the line string
    List<Point> points = simplifyPoints(lineString.getPoints());

    for (Point point : points) {
        LatLng latLng = toLatLng(point);
        polylineOptions.add(latLng);
        if (point.hasZ()) {
            z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
        }
    }

    if (lineString.hasZ() && z != null) {
        polylineOptions.zIndex(z.floatValue());
    }

    return polylineOptions;
}
 
Example 3
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 4
Source File: ViewRouteActivity.java    From JalanJalan with Do What The F*ck You Want To Public License 6 votes vote down vote up
private void drawDirectionToMap(List<LatLng> latLngList) {
    PolylineOptions line = new PolylineOptions().width(3).color(Color.BLUE);
    for (int i = 0; i < latLngList.size(); i++) {
        line.add(latLngList.get(i));
    }
    mMap.addPolyline(line);
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latLngList.get(0).latitude, latLngList.get(0).longitude), 14));

    // add marker diawal
    mMap.addMarker(new MarkerOptions()
                    .position(new LatLng(latLngList.get(0).latitude, latLngList.get(0).longitude))
                    .title("starting point")
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker))
    );

    // add marker di akhir
    int index = latLngList.size() - 1;
    mMap.addMarker(new MarkerOptions()
                    .position(new LatLng(latLngList.get(index).latitude, latLngList.get(index).longitude))
                    .title("end point")
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker))
    );

    Toast.makeText(this, "Jalur berhasil digambar kak, hati2 dijalan pelan2 saja,,, ", Toast.LENGTH_SHORT).show();
}
 
Example 5
Source File: MainActivity.java    From roads-api-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the GPX button-click event, running the demo snippet {@link #loadGpxData}.
 */
public void onGpxButtonClick(View view) {
    try {
        mCapturedLocations = loadGpxData(Xml.newPullParser(),
                getResources().openRawResource(R.raw.gpx_data));
        findViewById(R.id.snap_to_roads).setEnabled(true);

        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        PolylineOptions polyline = new PolylineOptions();

        for (LatLng ll : mCapturedLocations) {
            com.google.android.gms.maps.model.LatLng mapPoint =
                    new com.google.android.gms.maps.model.LatLng(ll.lat, ll.lng);
            builder.include(mapPoint);
            polyline.add(mapPoint);
        }

        mMap.addPolyline(polyline.color(Color.RED));
        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
    } catch (XmlPullParserException | IOException e) {
        e.printStackTrace();
        toastException(e);
    }
}
 
Example 6
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void drawPointLine(LatLng latLngDevice) {
    if (this.gglMapLocationManager != null && this.gglMapLocationManager.getDevLocation() != null) {
        Polyline polyline;
        if (this.polylineList != null) {
            for (Polyline polyline2 : this.polylineList) {
                polyline2.remove();
            }
            this.polylineList.clear();
        }
        for (int i = 0; i < this.mMarkerList.size(); i++) {
            PolylineOptions polylineOptions = new PolylineOptions();
            if (i == 0) {
                polylineOptions.add(latLngDevice);
                polylineOptions.add(((Marker) this.mMarkerList.get(i)).getPosition());
            } else {
                polylineOptions.add(((Marker) this.mMarkerList.get(i - 1)).getPosition());
                polylineOptions.add(((Marker) this.mMarkerList.get(i)).getPosition());
            }
            polylineOptions.color(this.context.getResources().getColor(this.lineDefaultColor)).zIndex(3.0f);
            polylineOptions.width(4.0f);
            polyline2 = this.googleMap.addPolyline(polylineOptions);
            polyline2.setPattern(PATTERN_DASHED);
            try {
                this.polylineList.add(polyline2);
            } catch (Exception e) {
            }
        }
    }
}
 
Example 7
Source File: GglMapAiSurroundManager.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void addPolylinescircle(boolean cw, double lat, double lng, double lat1, double lng2, int radius, int maxRadius) {
    if (this.line != null) {
        this.line.remove();
        this.line = null;
    }
    FLatLng centerpoint = GpsCorrect.Earth_To_Mars(lat, lng);
    FLatLng point = GpsCorrect.Earth_To_Mars(lat1, lng2);
    float angle = this.mapCalcAngle.getAngle2(new LatLng(centerpoint.latitude, centerpoint.longitude), new LatLng(point.latitude, point.longitude));
    PolylineOptions options = new PolylineOptions();
    int time = (int) Math.round((((double) (radius * 2)) * 3.141592653589793d) / 10.0d);
    if (time < 50) {
        time = 50;
    } else if (time > 180) {
        time = 180;
    }
    double temp = (double) ((((float) ((maxRadius + 10) - radius)) * 1.0f) / ((float) time));
    VisibleRegion visibleRegion = this.googleMap.getProjection().getVisibleRegion();
    LatLng farLeft = visibleRegion.farLeft;
    LatLng nearRight = visibleRegion.nearRight;
    float scale = GeoTools.getScale(farLeft, nearRight, this.googleMap.getProjection().toScreenLocation(nearRight).x - this.googleMap.getProjection().toScreenLocation(farLeft).x);
    for (int i = 0; i < 360; i++) {
        float startAngle;
        float t = (float) (((double) scale) * (((double) radius) + (((double) (((float) i) / (360.0f / ((float) time)))) * temp)));
        if (cw) {
            startAngle = ((float) i) + angle;
        } else {
            float cc = angle - ((float) i);
            if (cc < 0.0f) {
                startAngle = 360.0f + cc;
            } else {
                startAngle = cc;
            }
        }
        Point p1 = this.googleMap.getProjection().toScreenLocation(new LatLng(centerpoint.latitude, centerpoint.longitude));
        options.add(this.googleMap.getProjection().fromScreenLocation(new Point((int) (((double) p1.x) + (((double) t) * Math.cos((((double) startAngle) * 3.141592653589793d) / 180.0d))), (int) (((double) p1.y) + (((double) t) * Math.sin((((double) startAngle) * 3.141592653589793d) / 180.0d))))));
    }
    this.line = this.googleMap.addPolyline(options.width(3.0f));
    this.line.setColor(this.context.getResources().getColor(R.color.x8_drone_inface_line));
}
 
Example 8
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 9
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 10
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options.
 *
 * @param context         A context.
 * @param locationList    A list of latitude and longitude.
 * @param width           Width of the polyline in screen pixels.
 * @param color           Color of the polyline as a 32-bit ARGB color.
 * @param clickable       Is polyline clickable.
 * @param jointType       Joint type for all vertices of the polyline except the start and end vertices.
 * @param startCap        Cap at the start vertex of the polyline.
 * @param endCap          Cap at the end vertex of the polyline.
 * @param patternItemList Stroke pattern for the polyline.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static PolylineOptions createPolyline(
        @NonNull Context context,
        @Nullable ArrayList<LatLng> locationList,
        @Dimension(unit = Dimension.DP) int width,
        @ColorInt int color,
        boolean clickable,
        int jointType,
        @Nullable Cap startCap,
        @Nullable Cap endCap,
        @Nullable List<PatternItem> patternItemList) {
    PolylineOptions rectLine = new PolylineOptions().width(dpToPx(context, width)).color(color).geodesic(true);
    rectLine.clickable(clickable);
    rectLine.jointType(jointType);
    if (patternItemList != null) {
        rectLine.pattern(patternItemList);
    }
    if (startCap != null) {
        rectLine.startCap(startCap);
    }
    if (endCap != null) {
        rectLine.endCap(endCap);
    }
    if (locationList != null && locationList.size() > 0) {
        for (LatLng location : locationList) {
            rectLine.add(location);
        }
    }
    return rectLine;
}
 
Example 11
Source File: MapWrapper.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public int addPolyline(final Polyline aPolyline) {
	if (mPolylines == null) {
		mPolylines = new HashMap<Integer, com.google.android.gms.maps.model.Polyline>();
	}
	final PolylineOptions polylineOptions = new PolylineOptions().color(aPolyline.color).width(aPolyline.width);
	for(IGeoPoint point : aPolyline.points) {
		polylineOptions.add(new LatLng(point.getLatitude(), point.getLongitude()));
	}
	final com.google.android.gms.maps.model.Polyline polyline = mGoogleMap.addPolyline(polylineOptions);
	final int id = random.nextInt();
	mPolylines.put(id, polyline);
	return id;
}
 
Example 12
Source File: Principal.java    From ExamplesAndroid with Apache License 2.0 4 votes vote down vote up
public void success(DirectionResults directionResults) {
    Log.i("zacharia", "inside on success" +directionResults.getRoutes().size());
    ArrayList<LatLng> routelist = new ArrayList<LatLng>();
    if(directionResults.getRoutes().size()>0){
        ArrayList<LatLng> decodelist;
        Route routeA = directionResults.getRoutes().get(0);
        Log.i("zacharia", "Legs length : "+routeA.getLegs().size());
        if(routeA.getLegs().size()>0){
            List<Steps> steps= routeA.getLegs().get(0).getSteps();
            Log.i("zacharia","Steps size :"+steps.size());
            Steps step;
            com.tutorials.hackro.speedytaxi.Direction.Location location;
            String polyline;
            for(int i=0 ; i<steps.size();i++){
                step = steps.get(i);
                location =step.getStart_location();
                routelist.add(new LatLng(location.getLat(), location.getLng()));
                Log.i("zacharia", "Start Location :" + location.getLat() + ", " + location.getLng());
                polyline = step.getPolyline().getPoints();
                decodelist = RouteDecode.decodePoly(polyline);
                routelist.addAll(decodelist);
                location =step.getEnd_location();
                routelist.add(new LatLng(location.getLat() ,location.getLng()));
                Log.i("zacharia","End Location :"+location.getLat() +", "+location.getLng());
            }
        }
    }
    Log.i("zacharia","routelist size : "+routelist.size());
    if(routelist.size()>0){
        PolylineOptions rectLine = new PolylineOptions().width(10).color(
                Color.RED);

        for (int i = 0; i < routelist.size(); i++) {
            rectLine.add(routelist.get(i));
        }

        mGoogleMap.addPolyline(rectLine);


        // Adding route on the map

      /*  mMap.addPolyline(rectLine);
        markerOptions.position(toPosition);
        markerOptions.draggable(true);
        mMap.addMarker(markerOptions);*/
    }
}
 
Example 13
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);
    }
}