/** * Add this polyline to the given {@link GoogleMap} instance * * @param googleMap the {@link GoogleMap} instance to which the polyline will be added */ public void addToGoogleMap(GoogleMap googleMap) { // add the polyline and keep a reference so it can be removed googlePolyline = googleMap.addPolyline(new PolylineOptions() .addAll(points) .width(strokeWidth) .color(strokeColor)); }
/** * 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; }
/** * 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()); return polylineOptions; }
new PolylineOptions().add(new LatLng(40.70686417491799, -74.01572942733765), new LatLng(40.76866299974387, new LatLng(40.748963847316034, -73.96807193756104)) .width(5).color(Color.RED);
lineOptions = new PolylineOptions(); lineOptions.width(10); lineOptions.color(Color.BLACK); lineOptions.startCap(new SquareCap()); lineOptions.endCap(new SquareCap()); lineOptions.jointType(ROUND); blackPolyLine = mMap.addPolyline(lineOptions); PolylineOptions greyOptions = new PolylineOptions(); greyOptions.width(10); greyOptions.color(Color.GRAY); greyOptions.startCap(new SquareCap()); greyOptions.endCap(new SquareCap()); greyOptions.jointType(ROUND); greyPolyLine = mMap.addPolyline(greyOptions);
protected void testePolyline(GoogleMap map) { PolylineOptions line = new PolylineOptions(); line.add(new LatLng(-23.564391, -46.651717)); line.add(new LatLng(-23.565391, -46.652717)); line.add(new LatLng(-23.564282, -46.654337)); line.add(new LatLng(-23.563114, -46.653283)); line.add(new LatLng(-23.564391, -46.651717)); line.color(Color.BLUE); Polyline polyline = map.addPolyline(line); }
count++; googleMap.addPolyline( new PolylineOptions() .color(polyline.getUiOptions().getColor()) .width(polyline.getUiOptions().getWidth()) .pattern(getStrokePattern(polyline.getUiOptions().getStrokePattern())) .zIndex(polyline.getUiOptions().getzIndex()) .add(polyline.getPoints()) ); for (LatLng latLng : polyline.getPoints()) {
mMap.addPolyline(new PolylineOptions() .addAll(line) .color(Color.BLACK)); mMap.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.RED - ALPHA_ADJUSTMENT)); mMap.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.GREEN - ALPHA_ADJUSTMENT)); mMap.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.MAGENTA - ALPHA_ADJUSTMENT)); mMap.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.YELLOW - ALPHA_ADJUSTMENT)); mMap.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.BLUE - ALPHA_ADJUSTMENT));
@Override public void onCameraMoveStarted(int reason) { if (!isCanceled) { mMap.clear(); } String reasonText = "UNKNOWN_REASON"; currPolylineOptions = new PolylineOptions().width(5); switch (reason) { case OnCameraMoveStartedListener.REASON_GESTURE: currPolylineOptions.color(Color.BLUE); reasonText = "GESTURE"; break; case OnCameraMoveStartedListener.REASON_API_ANIMATION: currPolylineOptions.color(Color.RED); reasonText = "API_ANIMATION"; break; case OnCameraMoveStartedListener.REASON_DEVELOPER_ANIMATION: currPolylineOptions.color(Color.GREEN); reasonText = "DEVELOPER_ANIMATION"; break; } Log.i(TAG, "onCameraMoveStarted(" + reasonText + ")"); addCameraTargetToPath(); }
/** * Sets the color of the GeoJsonLineString as a 32-bit ARGB color * * @param color color value of the GeoJsonLineString */ public void setColor(int color) { mPolylineOptions.color(color); styleChanged(); }
void drawDebugGrid(IGoogleMap map, double clusterSize) { cleanup(); IProjection projection = map.getProjection(); LatLngBounds bounds = projection.getVisibleRegion().latLngBounds; double minY = -180 + clusterSize * (int) (SphericalMercator.scaleLatitude(bounds.southwest.latitude) / clusterSize); double minX = -180 + clusterSize * (int) (SphericalMercator.scaleLongitude(bounds.southwest.longitude) / clusterSize); double maxY = -180 + clusterSize * (int) (SphericalMercator.scaleLatitude(bounds.northeast.latitude) / clusterSize); double maxX = -180 + clusterSize * (int) (SphericalMercator.scaleLongitude(bounds.northeast.longitude) / clusterSize); for (double y = minY; y <= maxY; y += clusterSize) { gridLines.add(map.addPolyline(new PolylineOptions().width(1.0f).add(new LatLng(SphericalMercator.toLatitude(y), bounds.southwest.longitude), new LatLng(SphericalMercator.toLatitude(y), bounds.northeast.longitude)))); } if (minX <= maxX) { for (double x = minX; x <= maxX; x += clusterSize) { gridLines.add(map.addPolyline(new PolylineOptions().width(1.0f).add(new LatLng(bounds.southwest.latitude, x), new LatLng(bounds.northeast.latitude, x)))); } } else { for (double x = -180; x <= minX; x += clusterSize) { gridLines.add(map.addPolyline(new PolylineOptions().width(1.0f).add(new LatLng(bounds.southwest.latitude, x), new LatLng(bounds.northeast.latitude, x)))); } for (double x = maxX; x < 180; x += clusterSize) { gridLines.add(map.addPolyline(new PolylineOptions().width(1.0f).add(new LatLng(bounds.southwest.latitude, x), new LatLng(bounds.northeast.latitude, x)))); } } }
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); mMap.animateCamera(CameraUpdateFactory.zoomTo(17)); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } PolylineOptions polylineOptions = new PolylineOptions() .color(Color.CYAN) .geodesic(true); mPolyline = mMap.addPolyline(polylineOptions); }
@Override protected void startDemo() { List<LatLng> decodedPath = PolyUtil.decode(LINE); getMap().addPolyline(new PolylineOptions().addAll(decodedPath)); getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 12)); } }
/** * Sets the width of the LineString in screen pixels * * @param width width value of the LineString */ public void setLineStringWidth(float width) { mPolylineOptions.width(width); }
/** * Creates a new LineStringStyle object */ public GeoJsonLineStringStyle() { mPolylineOptions = new PolylineOptions(); }
/** * Adds a KML LineString to the map as a Polyline by combining the styling and coordinates * * @param lineString contains coordinates for the Polyline * @param style contains relevant styling properties for the Polyline * @return Polyline object */ private Polyline addLineStringToMap(KmlLineString lineString, KmlStyle style, KmlStyle inlineStyle) { PolylineOptions polylineOptions = style.getPolylineOptions(); polylineOptions.addAll(lineString.getGeometryObject()); if (inlineStyle != null) { setInlineLineStringStyle(polylineOptions, inlineStyle); } else if (style.isLineRandomColorMode()) { polylineOptions.color(KmlStyle.computeRandomColor(polylineOptions.getColor())); } return mMap.addPolyline(polylineOptions); }
@Override protected void startDemo() { mTextView = (TextView) findViewById(R.id.textView); getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 10)); getMap().setOnMarkerDragListener(this); mMarkerA = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.9046, 151.155)).draggable(true)); mMarkerB = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.8291, 151.248)).draggable(true)); mPolyline = getMap().addPolyline(new PolylineOptions().geodesic(true)); Toast.makeText(this, "Drag the markers!", Toast.LENGTH_LONG).show(); showDistance(); }
private void addCameraTargetToPath() { LatLng target = mMap.getCameraPosition().target; currPolylineOptions.add(target); } }
/** * Adds a LineString to the map as a Polyline * * @param polylineOptions contains relevant styling properties for the Polyline * @param lineString contains coordinates for the Polyline * @return Polyline object created from given LineString */ protected Polyline addLineStringToMap(PolylineOptions polylineOptions, LineString lineString) { // Add coordinates polylineOptions.addAll(lineString.getGeometryObject()); Polyline addedPolyline = mMap.addPolyline(polylineOptions); addedPolyline.setClickable(true); return addedPolyline; }