com.google.android.gms.maps.model.Polyline Java Examples

The following examples show how to use com.google.android.gms.maps.model.Polyline. 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: 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 #2
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Given a Marker, Polyline, Polygon or an array of these and removes it from the map
 *
 * @param mapObject map object or array of map objects to remove from the map
 */
protected void removeFromMap(Object mapObject) {
    if (mapObject instanceof Marker) {
        mMarkers.remove((Marker) mapObject);
    } else if (mapObject instanceof Polyline) {
        mPolylines.remove((Polyline) mapObject);
    } else if (mapObject instanceof Polygon) {
        mPolygons.remove((Polygon) mapObject);
    } else if (mapObject instanceof GroundOverlay) {
        mGroundOverlays.remove((GroundOverlay) mapObject);
    } else if (mapObject instanceof ArrayList) {
        for (Object mapObjectElement : (ArrayList) mapObject) {
            removeFromMap(mapObjectElement);
        }
    }
}
 
Example #3
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 #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: TrackPathUtils.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Add a path.
 * 
 * @param googleMap the google map
 * @param paths the existing paths
 * @param points the path points
 * @param color the path color
 * @param append true to append to the last path
 */
public static void addPath(GoogleMap googleMap, ArrayList<Polyline> paths,
    ArrayList<LatLng> points, int color, boolean append) {
  if (points.size() == 0) {
    return;
  }
  if (append && paths.size() != 0) {
    Polyline lastPolyline = paths.get(paths.size() - 1);
    ArrayList<LatLng> pathPoints = new ArrayList<LatLng>();
    pathPoints.addAll(lastPolyline.getPoints());
    pathPoints.addAll(points);
    lastPolyline.setPoints(pathPoints);
  } else {
    PolylineOptions polylineOptions = new PolylineOptions().addAll(points).width(5).color(color);
    Polyline polyline = googleMap.addPolyline(polylineOptions);
    paths.add(polyline);
  }
  points.clear();
}
 
Example #6
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 #7
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void clearMarker() {
    if (this.polylineList != null) {
        for (Polyline polyline : this.polylineList) {
            polyline.remove();
        }
    }
    if (this.limitCircle != null) {
        this.limitCircle.remove();
        this.limitCircle = null;
    }
    this.polylineList.clear();
    this.mMarkerList.clear();
    this.mMapPointList.clear();
    this.interestMarkerList.clear();
    this.arrowMarkerList.clear();
    this.mSelectMarker = null;
}
 
Example #8
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 #9
Source File: MapOverlay.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the track, start and end markers, and waypoints.
 * 
 * @param googleMap the google map
 * @param paths the paths
 * @param tripStatistics the trip statistics
 * @param reload true to reload all points
 * @return true if has the start marker
 */
public boolean update(GoogleMap googleMap, ArrayList<Polyline> paths,
    TripStatistics tripStatistics, boolean reload) {
  synchronized (locations) {
    boolean hasStartMarker = false;
    // Merge pendingLocations with locations
    int newLocations = pendingLocations.drainTo(locations);
    // Call updateState first because we want to update its state each time
    // (for dynamic coloring)
    if (trackPath.updateState(tripStatistics) || reload) {
      googleMap.clear();
      paths.clear();
      trackPath.updatePath(googleMap, paths, 0, locations);
      hasStartMarker = updateStartAndEndMarkers(googleMap);
      updateWaypoints(googleMap);
    } else {
      if (newLocations != 0) {
        int numLocations = locations.size();
        trackPath.updatePath(googleMap, paths, numLocations - newLocations, locations);
      }
    }
    return hasStartMarker;
  }
}
 
Example #10
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Adds all GeoJsonLineString objects in the GeoJsonMultiLineString to the map as multiple
 * Polylines
 *
 * @param lineStringStyle contains relevant styling properties for the Polylines
 * @param multiLineString contains an array of GeoJsonLineStrings
 * @return array of Polylines that have been added to the map
 */
private ArrayList<Polyline> addMultiLineStringToMap(GeoJsonLineStringStyle lineStringStyle,
                                                    GeoJsonMultiLineString multiLineString) {
    ArrayList<Polyline> polylines = new ArrayList<>();
    for (GeoJsonLineString geoJsonLineString : multiLineString.getLineStrings()) {
        polylines.add(addLineStringToMap(lineStringStyle.toPolylineOptions(), geoJsonLineString));
    }
    return polylines;
}
 
Example #11
Source File: PolylineManager.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
@Override
public void onPolylineClick(Polyline polyline) {
    Collection collection = mAllObjects.get(polyline);
    if (collection != null && collection.mPolylineClickListener != null) {
        collection.mPolylineClickListener.onPolylineClick(polyline);
    }
}
 
Example #12
Source File: PolyActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Styles the polyline, based on type.
 * @param polyline The polyline object that needs styling.
 */
private void stylePolyline(Polyline polyline) {
    String type = "";
    // Get the data object stored with the polyline.
    if (polyline.getTag() != null) {
        type = polyline.getTag().toString();
    }

    switch (type) {
        // If no type is given, allow the API to use the default.
        case "A":
            // Use a custom bitmap as the cap at the start of the line.
            polyline.setStartCap(
                    new CustomCap(
                            BitmapDescriptorFactory.fromResource(R.drawable.ic_arrow), 10));
            break;
        case "B":
            // Use a round cap at the start of the line.
            polyline.setStartCap(new RoundCap());
            break;
    }

    polyline.setEndCap(new RoundCap());
    polyline.setWidth(POLYLINE_STROKE_WIDTH_PX);
    polyline.setColor(COLOR_BLACK_ARGB);
    polyline.setJointType(JointType.ROUND);
}
 
Example #13
Source File: CurveManager.java    From Curve-Fit with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    // Runs on UI thread
    if (msg.what == Constants.TASK_COMPLETE) {
        CurveOptions curveOptions = (CurveOptions) msg.obj;
        // Draws curve on map
        Polyline real = googleMap.addPolyline(curveOptions.getReal());
        Curve curve = new DelegatingCurve(real, CurveManager.this);
        curves.put(real, curve);
        if (onCurveDrawnCallback != null) {
            onCurveDrawnCallback.onCurveDrawn(curve);
        }
    }
}
 
Example #14
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public Polyline getPolyline(int index, Polyline pl, int color) {
    PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.addAll(pl.getPoints());
    polylineOptions.color(this.context.getResources().getColor(color)).zIndex(3.0f);
    polylineOptions.width(4.0f);
    Polyline line = this.googleMap.addPolyline(polylineOptions);
    line.setPattern(PATTERN_DASHED);
    return line;
}
 
Example #15
Source File: GeoTools.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static List<Polyline> drawDashedPolyLine(GoogleMap mMap, ArrayList<LatLng> listOfPoints, int color) {
    List<Polyline> tracklines = new ArrayList();
    boolean added = false;
    for (int i = 0; i < listOfPoints.size() - 1; i++) {
        double distance = getConvertedDistance((LatLng) listOfPoints.get(i), (LatLng) listOfPoints.get(i + 1));
        if (distance >= 0.02d) {
            int countOfDivisions = (int) (distance / 0.02d);
            double latdiff = (((LatLng) listOfPoints.get(i + 1)).latitude - ((LatLng) listOfPoints.get(i)).latitude) / ((double) countOfDivisions);
            double lngdiff = (((LatLng) listOfPoints.get(i + 1)).longitude - ((LatLng) listOfPoints.get(i)).longitude) / ((double) countOfDivisions);
            LatLng lastKnowLatLng = new LatLng(((LatLng) listOfPoints.get(i)).latitude, ((LatLng) listOfPoints.get(i)).longitude);
            for (int j = 0; j < countOfDivisions; j++) {
                LatLng nextLatLng = new LatLng(lastKnowLatLng.latitude + latdiff, lastKnowLatLng.longitude + lngdiff);
                if (added) {
                    added = false;
                } else {
                    tracklines.add(mMap.addPolyline(new PolylineOptions().add(lastKnowLatLng).add(nextLatLng).color(color)));
                    added = true;
                }
                lastKnowLatLng = nextLatLng;
            }
        } else if (added) {
            added = false;
        } else {
            tracklines.add(mMap.addPolyline(new PolylineOptions().add((LatLng) listOfPoints.get(i)).add((LatLng) listOfPoints.get(i + 1)).color(color)));
            added = true;
        }
    }
    return tracklines;
}
 
Example #16
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void changeLine() {
    if (this.mMarkerList != null && this.nPos == -1 && this.polylineList != null && this.polylineList.size() > 0) {
        Polyline c = (Polyline) this.polylineList.get(0);
        List<LatLng> mLatLng = new ArrayList();
        mLatLng.add(this.gglMapLocationManager.getDevLocation());
        mLatLng.add(((Marker) this.mMarkerList.get(0)).getPosition());
        c.setPoints(mLatLng);
    }
}
 
Example #17
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 #18
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
private Polyline addLineStringToMap(PolylineOptions polylineOptions,
                                    LineString lineString) {
    // Add coordinates
    polylineOptions.addAll(lineString.getGeometryObject());
    Polyline addedPolyline = mPolylines.addPolyline(polylineOptions);
    addedPolyline.setClickable(polylineOptions.isClickable());
    return addedPolyline;
}
 
Example #19
Source File: CampusMapActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
/**
 * Does the actual drawing of the route polyline, based on the geo points provided in the navset
 *
 * @param navSet Navigation set bean that holds the route information, incl. geo pos
 * @param color  Color in which to draw the lines
 */
private void drawPath(Deque<LatLng> navSet, int color) {
    clearAllMapRoutes();
    PolylineOptions polyOpt = new PolylineOptions()
            .color(color)
            .width(5f);
    polyOpt.addAll(navSet);
    Polyline routePolyline = mMap.addPolyline(polyOpt);
    polylineMap.put(routePolyline.getId(), routePolyline);
}
 
Example #20
Source File: PolyActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Listens for clicks on a polyline.
 * @param polyline The polyline object that the user has clicked.
 */
@Override
public void onPolylineClick(Polyline polyline) {
    // Flip from solid stroke to dotted stroke pattern.
    if ((polyline.getPattern() == null) || (!polyline.getPattern().contains(DOT))) {
        polyline.setPattern(PATTERN_POLYLINE_DOTTED);
    } else {
        // The default pattern is a solid stroke.
        polyline.setPattern(null);
    }

    Toast.makeText(this, "Route type " + polyline.getTag().toString(),
            Toast.LENGTH_SHORT).show();
}
 
Example #21
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all given Features from the map and clears all stored features.
 *
 * @param features features to remove
 */
private void removeFeatures(Collection features) {
    // Remove map object from the map
    for (Object mapObject : features) {
        if (mapObject instanceof Collection) {
            removeFeatures((Collection) mapObject);
        } else if (mapObject instanceof Marker) {
            mMarkers.remove((Marker) mapObject);
        } else if (mapObject instanceof Polyline) {
            mPolylines.remove((Polyline) mapObject);
        } else if (mapObject instanceof Polygon) {
            mPolygons.remove((Polygon) mapObject);
        }
    }
}
 
Example #22
Source File: PolylineClickFuncTest.java    From RxGoogleMaps with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEmmitPolyline() throws Exception {
    TestSubscriber<Polyline> testSubscriber = new TestSubscriber<>();
    new PolylineClickFunc().call(googleMap)
            .subscribe(testSubscriber);
    verify(googleMap).setOnPolylineClickListener(argumentCaptor.capture());
    argumentCaptor.getValue().onPolylineClick(null);
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    argumentCaptor.getValue().onPolylineClick(null);
    testSubscriber.assertValueCount(2);
}
 
Example #23
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a list of {@link Polyline} to a {@link MultiLineString}
 *
 * @param polylineList polyline list
 * @param hasZ         has z flag
 * @param hasM         has m flag
 * @return multi line string
 */
public MultiLineString toMultiLineString(List<Polyline> polylineList,
                                         boolean hasZ, boolean hasM) {

    MultiLineString multiLineString = new MultiLineString(hasZ, hasM);

    for (Polyline polyline : polylineList) {
        LineString lineString = toLineString(polyline);
        multiLineString.addLineString(lineString);
    }

    return multiLineString;
}
 
Example #24
Source File: StaticGeometryCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
public Collection<Polyline> getPolylines() {
	Collection<Polyline> polylines = new ArrayList<Polyline>();
	for (Map.Entry<String, Collection<Polyline>> entry : featurePolylines.entrySet()) {
		for (Polyline p : entry.getValue()) {
			polylines.add(p);
		}
	}
	return polylines;
}
 
Example #25
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a list of {@link Polyline} to a {@link CompoundCurve}
 *
 * @param polylineList polyline list
 * @param hasZ         has z flag
 * @param hasM         has m flag
 * @return compound curve
 */
public CompoundCurve toCompoundCurve(List<Polyline> polylineList,
                                     boolean hasZ, boolean hasM) {

    CompoundCurve compoundCurve = new CompoundCurve(hasZ, hasM);

    for (Polyline polyline : polylineList) {
        LineString lineString = toLineString(polyline);
        compoundCurve.addLineString(lineString);
    }

    return compoundCurve;
}
 
Example #26
Source File: StaticGeometryCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
public void addPolyline(String layerId, Polyline polyline, String popupHTML) {
	if (featurePolylines.get(layerId) == null) {
		featurePolylines.put(layerId, new ArrayList<Polyline>());
	}

	featurePolylines.get(layerId).add(polyline);
	featurePolylineDescriptions.put(polyline, popupHTML);
}
 
Example #27
Source File: SingleColorTrackPath.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@Override
public void updatePath(GoogleMap googleMap, ArrayList<Polyline> paths, int startIndex,
    List<CachedLocation> locations) {
  if (googleMap == null) {
    return;
  }
  if (startIndex >= locations.size()) {
    return;
  }

  boolean newSegment = startIndex == 0 || !locations.get(startIndex - 1).isValid();
  ArrayList<LatLng> lastSegmentPoints = new ArrayList<LatLng>();
  boolean useLastPolyline = true;
  for (int i = startIndex; i < locations.size(); i++) {
    CachedLocation cachedLocation = locations.get(i);

    // If not valid, start a new segment
    if (!cachedLocation.isValid()) {
      newSegment = true;
      continue;
    }
    LatLng latLng = cachedLocation.getLatLng();
    if (newSegment) {
      TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, color, useLastPolyline);
      useLastPolyline = false;
      newSegment = false;
    }
    lastSegmentPoints.add(latLng);
  }
  TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, color, useLastPolyline);
}
 
Example #28
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
/**
 * Sets a single click listener for each of the map object collections, that will be called
 * with the corresponding Feature object when an object on the map (Polygon, Marker, Polyline)
 * from one of this Renderer's collections is clicked.
 *
 * If getFeature() returns null this means that either the object is inside a KMLContainer,
 * or the object is a MultiPolygon, MultiLineString or MultiPoint and must
 * be handled differently.
 *
 * @param listener Listener providing the onFeatureClick method to call.
 */
void setOnFeatureClickListener(final Layer.OnFeatureClickListener listener) {

    mPolygons.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
        @Override
        public void onPolygonClick(Polygon polygon) {
            if (getFeature(polygon) != null) {
                listener.onFeatureClick(getFeature(polygon));
            } else if (getContainerFeature(polygon) != null) {
                listener.onFeatureClick(getContainerFeature(polygon));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(polygon)));
            }
        }
    });

    mMarkers.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            if (getFeature(marker) != null) {
                listener.onFeatureClick(getFeature(marker));
            }  else if (getContainerFeature(marker) != null) {
                listener.onFeatureClick(getContainerFeature(marker));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(marker)));
            }
            return false;
        }
    });

    mPolylines.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
        @Override
        public void onPolylineClick(Polyline polyline) {
            if (getFeature(polyline) != null) {
                listener.onFeatureClick(getFeature(polyline));
            } else if (getContainerFeature(polyline) != null) {
                listener.onFeatureClick(getContainerFeature(polyline));
            }  else {
                listener.onFeatureClick(getFeature(multiObjectHandler(polyline)));
            }
        }
    });
}
 
Example #29
Source File: TagsDemoActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onPolylineClick(Polyline polyline) {
    onClick((CustomTag) polyline.getTag());
}
 
Example #30
Source File: MultiColorTrackPath.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@Override
public void updatePath(GoogleMap googleMap, ArrayList<Polyline> paths, int startIndex,
    List<CachedLocation> locations) {
  if (googleMap == null) {
    return;
  }
  if (startIndex >= locations.size()) {
    return;
  }
  
  boolean newSegment = startIndex == 0 || !locations.get(startIndex - 1).isValid();
  LatLng lastLatLng = startIndex != 0 ? locations.get(startIndex -1).getLatLng() : null;
  
  ArrayList<LatLng> lastSegmentPoints = new ArrayList<LatLng>();
  int lastSegmentColor = paths.size() != 0  ? paths.get(paths.size() - 1).getColor() : slowColor;
  boolean useLastPolyline = true;

  for (int i = startIndex; i < locations.size(); ++i) {
    CachedLocation cachedLocation = locations.get(i);

    // If not valid, start a new segment
    if (!cachedLocation.isValid()) {
      newSegment = true;
      lastLatLng = null;
      continue;
    }
    LatLng latLng = cachedLocation.getLatLng();
    int color = getColor(cachedLocation.getSpeed());
    
    // Either update point or draw a line from the last point
    if (newSegment) {
      TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, lastSegmentColor, useLastPolyline);
      useLastPolyline = false;
      lastSegmentColor = color;
      newSegment = false;
    }
    if (lastSegmentColor == color) {
      lastSegmentPoints.add(latLng);
    } else {
      TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, lastSegmentColor, useLastPolyline);
      useLastPolyline = false;
      if (lastLatLng != null) {
        lastSegmentPoints.add(lastLatLng);
      }
      lastSegmentPoints.add(latLng);
      lastSegmentColor = color;
    }
    lastLatLng = latLng;
  }
  TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, lastSegmentColor, useLastPolyline);
}