public static void zoomToPolyline(GoogleMap map, Polyline p) { if (p == null || p.getPoints().isEmpty()) return; LatLngBounds.Builder builder = LatLngBounds.builder(); for (LatLng latLng : p.getPoints()) { builder.include(latLng); } final LatLngBounds bounds = builder.build(); try{ map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 150)); } catch (Exception e){ e.printStackTrace(); } }
private View.OnClickListener getClickListener(final GpxTreeItem value) { return new View.OnClickListener() { @Override public void onClick(View v) { switch (value.type) { case ITEM_TYPE_TRACK: Polyline polyline = value.polylines[0]; MapUtils.zoomToPolyline(manager.getCurrentMap(), polyline); value.polylines[0].setColor(CHOSEN_TRACK_COLOR); value.polylines[0].setZIndex(ZINDEX_POLYLINE_CHOSEN); if (lastClickedPolyline != null) { lastClickedPolyline.setColor(DEFAULT_TRACK_COLOR); lastClickedPolyline.setZIndex(ZINDEX_POLYLINE); } lastClickedPolyline = polyline; break; case ITEM_TYPE_WAYPOINT: MapUtils.zoomToMarker(manager.getCurrentMap(), value.marker); break; } } }; }
/** * Add a Polyline to the map as markers * * @param map * @param polylineOptions * @param polylineMarkerOptions * @param globalPolylineOptions * @return */ 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()); } Polyline polyline = addPolylineToMap(map, polylineOptions); polylineMarkers.setPolyline(polyline); List<Marker> markers = addPointsToMapAsMarkers(map, polylineOptions.getPoints(), polylineMarkerOptions, false); polylineMarkers.setMarkers(markers); return polylineMarkers; }
private void addInterval(Context context, GoogleMap map, ProcessedDataModel item, boolean addCache) { double[] coordsStart = item.getCoordsStart(); double[] coordsEnd = item.getCoordsStart(); if (coordsStart == null || coordsEnd == null || coordsStart.length < 2 || coordsEnd.length < 2) { return; } LatLng startLine = new LatLng(item.getCoordsStart()[0], item.getCoordsStart()[1]); LatLng endLine = new LatLng(item.getCoordsEnd()[0], item.getCoordsEnd()[1]); Polyline line = map.addPolyline(new PolylineOptions() .add(startLine, endLine) .geodesic(true) .width(context.getResources().getDimension(R.dimen.map_polyline_width)) .color(getIriColor(context, item.getCategory()))); if (addCache && linesCache != null) { linesCache.put(line, item); } }
/** * @param graph to use in drawing polyOptions on the graph. */ @Override public void drawGraph(Graph graph) { PolylineOptions graphOptions = new PolylineOptions(); List<Location> locationList = graph.getLocations(); for (Location location: locationList){ LatLng currentPosition = new LatLng(location.getLatitude(), location.getLongitude()); MarkerOptions options = new MarkerOptions(); options.position(currentPosition) .icon(BitmapDescriptorFactory.defaultMarker()) .title("Position") .snippet("Some Position"); googleMap.addMarker(options); graphOptions.add(currentPosition); } Polyline graphPolygon = googleMap.addPolyline(graphOptions); graphPolygon.setGeodesic(true); graphPolygon.setColor(Color.DKGRAY); graphPolygon.setWidth(20); }
/** * Helper function used to draw routes on the map given 2 locations * * @param mMap * @param decodedPolyLine * @param polylineArrayList * @return */ public int drawRoute(GoogleMap mMap, List<LatLng> decodedPolyLine, ArrayList<Polyline> polylineArrayList) { int routeDistance = 0; for (int i = 0; i < (decodedPolyLine.size() - 1); i++) { LatLng point1 = decodedPolyLine.get(i); LatLng point2 = decodedPolyLine.get(i + 1); Location location1 = new Location("1"); location1.setLatitude(point1.latitude); location1.setLongitude(point1.longitude); Location location2 = new Location("2"); location2.setLatitude(point2.latitude); location2.setLongitude(point2.longitude); routeDistance += location1.distanceTo(location2); polylineArrayList.add(mMap.addPolyline(new PolylineOptions() .add(point1, point2) .width(5) .color(Color.RED))); } return routeDistance; }
public void setTracksVisible(boolean visible) { for (Map.Entry<String, Polyline> entry : mRoutesMap.entrySet()) { Polyline route = entry.getValue(); if (route != null) { Marker start = mRouteStartMarksMap.get(route); if (start != null) { start.setVisible(visible); } Marker end = mRouteEndMarksMap.get(route); if (end != null) { end.setVisible(visible); } route.setVisible(visible); } } }
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; }
/** * Remove the polyline * @param args * @param callbackContext * @throws JSONException */ @SuppressWarnings("unused") private void remove(final JSONArray args, final CallbackContext callbackContext) throws JSONException { String id = args.getString(1); Polyline polyline = this.getPolyline(id); if (polyline == null) { this.sendNoResult(callbackContext); return; } this.objects.remove(id); id = "polyline_bounds_" + polyline.getId(); this.objects.remove(id); polyline.remove(); this.sendNoResult(callbackContext); }
/** * Set points * @param args * @param callbackContext * @throws JSONException */ @SuppressWarnings("unused") private void setPoints(final JSONArray args, final CallbackContext callbackContext) throws JSONException { String id = args.getString(1); Polyline polyline = this.getPolyline(id); JSONArray points = args.getJSONArray(2); List<LatLng> path = PluginUtil.JSONArray2LatLngList(points); polyline.setPoints(path); LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (int i = 0; i < path.size(); i++) { builder.include(path.get(i)); } this.objects.put("polyline_bounds_" + polyline.getId(), builder.build()); this.sendNoResult(callbackContext); }
@Override public void call(final Subscriber<? super Polyline> subscriber) { GoogleMap.OnPolylineClickListener listener = new GoogleMap.OnPolylineClickListener() { @Override public void onPolylineClick(Polyline polyline) { if (!subscriber.isUnsubscribed()) { subscriber.onNext(polyline); } } }; googleMap.setOnPolylineClickListener(listener); subscriber.add(Subscriptions.create(new Action0() { @Override public void call() { googleMap.setOnPolylineClickListener(null); } })); }
@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); } }
/** * 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; } }
/** * 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(); }
/** draw the route on the map, if there is a created route, * It will be removed to create another. * */ private void drawRoute(List<LatLng> latlngList){ if(latlngList != null){ if(polylineList != null){ for(Polyline polyline : polylineList){ polyline.remove(); } } polylineList = new ArrayList<Polyline>(); for (int i = 0; i < latlngList.size() - 1; i++) { LatLng src = latlngList.get(i); LatLng dest = latlngList.get(i + 1); Polyline polyLine = mMap.addPolyline( new PolylineOptions() .add(new LatLng(src.latitude, src.longitude), new LatLng(dest.latitude,dest.longitude)) .width(4) .color(Color.BLUE) .geodesic(true)); polylineList.add(polyLine); } } }
/** * Drw polyline on the Google Map from first and last LatLng * @param first start point of the polyline to draw * @param last last point of the polyline to draw */ public void drawLine(LatLng first, LatLng last){ // First you need rotate the bitmap of the arrowhead somewhere in your code float rotationDegrees = (float) LatLngUtils.angleFromCoordinate(last.latitude, last.longitude, first.latitude, first.longitude); // Create the rotated arrowhead bitmap Bitmap arrow = BitmapFactory.decodeResource(getResources(), R.drawable.arrow); BitmapDescriptor bitmapDescriptorFactory = BitmapDescriptorFactory.fromBitmap(arrow); // Get the middle position LatLng middlePos = LatLngUtils.midPoint(first.latitude, first.longitude, last.latitude, last.longitude); // Now we are gonna to add a marker Marker mArrowhead = googleMap.addMarker(new MarkerOptions() .position(middlePos) .flat(true) .anchor(0.5f, 0.5f) .rotation(rotationDegrees) .icon(bitmapDescriptorFactory)); Polyline line = googleMap.addPolyline((new PolylineOptions()) .add(first, last).width(3).color(Color.parseColor("#9b24a6")) .geodesic(true)); polylines.add(new Pair<Polyline, Marker>(line, mArrowhead)); }
/** * Adds a single geometry object to the map with its specified style * * @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 */ private Object addToMap(KmlPlacemark placemark, KmlGeometry geometry, KmlStyle style, KmlStyle inlineStyle, boolean isVisible) { String geometryType = geometry.getGeometryType(); if (geometryType.equals("Point")) { Marker marker = addPointToMap(placemark, (KmlPoint) geometry, style, inlineStyle); marker.setVisible(isVisible); return marker; } else if (geometryType.equals("LineString")) { Polyline polyline = addLineStringToMap((KmlLineString) geometry, style, inlineStyle); polyline.setVisible(isVisible); return polyline; } else if (geometryType.equals("Polygon")) { Polygon polygon = addPolygonToMap((KmlPolygon) geometry, style, inlineStyle); polygon.setVisible(isVisible); return polygon; } else if (geometryType.equals("MultiGeometry")) { return addMultiGeometryToMap(placemark, (KmlMultiGeometry) geometry, style, inlineStyle, isVisible); } return null; }
private void clearNav() { mNavigating = false; mStartingLocation = null; mStartingLocationButton.setText(R.string.your_location); hideNav(); mNavSelectionFab.setImageResource(R.drawable.ic_directions_black_24dp); if (mDestinationMarker != null) { mDestinationMarker.remove(); mDestinationMarker = null; } MapData.cleanTempNodes(); if (mNavPathPolylines != null) { for (Polyline line : mNavPathPolylines) { if (line != null) { line.remove(); } } mNavPathPolylines = null; } if (mDebugMode) { getMap().subscribe(this::updateMapOverlays); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.google_map); if (googleHarita == null) { googleHarita = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.haritafragment)) .getMap(); if (googleHarita != null) { Polyline line = googleHarita.addPolyline(new PolylineOptions() .add(new LatLng(41.061071, 28.949268), new LatLng(41.060845, 28.949569), new LatLng(41.060715, 28.949826), new LatLng(41.060553, 28.950084)) .width(5) .color(Color.RED)); } } }
private void drawMap(HashMap<String, TrailObj> trailCollection, GoogleMap mMap2) { // TODO Auto-generated method stub for (TrailObj trail : trailCollection.values()) { for (PlacemarkObj p : trail.getPlacemarks()) { PolylineOptions rectOptions = new PolylineOptions(); for (LatLng g : p.getCoordinates()) { rectOptions.add(g); } Polyline polyline = mMap2.addPolyline(rectOptions); polyline.setColor(Color.RED); polyline.setWidth(5); polyline.setVisible(true); } } }
public void drawTrailByName(GoogleMap map, String trailName) { DatabaseHelper db; db = new DatabaseHelper(this); ArrayList<Placemark> placemarks = db.getTrailPlacemarks(trailName); ArrayList<GeoPoint> points; PolylineOptions rectOptions; for (Placemark p : placemarks) { rectOptions = new PolylineOptions(); points = db.getPlacemarkGeoPoints(p.getId()); for (GeoPoint g : points) { rectOptions.add(new LatLng(g.getLat(), g.getLng())); } Polyline polyline = map.addPolyline(rectOptions); polyline.setColor(Color.RED); polyline.setWidth(8); polyline.setVisible(true); } }
public void drawTrail(GoogleMap map, TrailObj trail) { ArrayList<LatLng> allPoints = new ArrayList<LatLng>(); ArrayList<GeoPoint> points; PolylineOptions rectOptions; for (PlacemarkObj p : trail.getPlacemarks()) { rectOptions = new PolylineOptions(); allPoints.addAll(p.getCoordinates()); for (LatLng g : p.getCoordinates()) { rectOptions.add(g); } Polyline polyline = map.addPolyline(rectOptions); polyline.setColor(Color.RED); polyline.setWidth(8); polyline.setVisible(true); } // map.addMarker(new MarkerOptions() // .position(center) // .title(trail.getTrailName())); }
public void drawTrails(GoogleMap map) { DatabaseHelper db; db = new DatabaseHelper(this); ArrayList<ArrayList<GeoPoint>> sortedGeoPoints = db.getPlacemarks(); int count = 0; int pCount = 0; PolylineOptions rectOptions; for (ArrayList<GeoPoint> p : sortedGeoPoints) { rectOptions = new PolylineOptions(); pCount++; for (GeoPoint g : p) { rectOptions.add(new LatLng(g.getLat(), g.getLng())); count++; } Polyline polyline = map.addPolyline(rectOptions); polyline.setColor(Color.RED); polyline.setWidth(8); polyline.setVisible(true); } map.addMarker(new MarkerOptions().position(new LatLng(43.95, -79.95)) .title(String.valueOf(count) + " " + String.valueOf(pCount))); System.out.println("When reading from db:" + count); }
private void parseRoute(XmlResourceParser xpp, String routeName) throws IOException, XmlPullParserException { PolylineOptions polylineOptions = new PolylineOptions(); while (xpp.nextTag() == XmlPullParser.START_TAG) { if (xpp.getName().equals("LatLng")) { String coords[] = xpp.nextText().split(","); polylineOptions.add(new LatLng(Double.valueOf(coords[0]), Double.valueOf(coords[1]))); } else if (xpp.getName().equals("Color")) { Polyline polyline = mMap.addPolyline(polylineOptions); String color = xpp.nextText(); polyline.setColor(Color.parseColor(color)); setPolyline(polyline, routeName); } else if (xpp.getName().equals("Width")) { getPolyline(routeName).setWidth(Float.valueOf(xpp.nextText())); } } }
@Override public void onDirectionFinderStart() { callProgressDialog(); if (polylinePaths != null) { for (Polyline polyline : polylinePaths) { polyline.remove(); } } }
@Override public void onMapReady(GoogleMap googleMap) { // Map is ready to be used. mMap = googleMap; // Set the long click listener as a way to exit the map. mMap.setOnMapLongClickListener(this); mMap.setOnMapClickListener(this); mMap.setOnMarkerDragListener(this); mMap.setOnInfoWindowClickListener(this); mMap.getUiSettings().setZoomControlsEnabled(true); mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); if (checkPermission()) { mMap.setMyLocationEnabled(true); } else { } // Add a marker in Sydney, Australia and move the camera. Polyline line = mMap.addPolyline(new PolylineOptions() .add(new LatLng(-34, 151), new LatLng(-37, 74.0)) .width(5) .color(Color.WHITE)); LatLng sydney = new LatLng(-34, 151); mMap.setInfoWindowAdapter(new WearInfoWindowAdapter(getLayoutInflater(), mMemories)); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); }
/** * * NOTE: cannot draw a polyline if there are no points, or only single point, specified in the PolylineOptions given as argument * * @param uuid path uuid * @param polylineOptions polyline options * @return true if polyline has been successfully added to Google Maps, false otherwise */ public boolean addPolylineToPath(String uuid, PolylineOptions polylineOptions) { if(polylineOptions.getPoints()==null || polylineOptions.getPoints().size()<2) { // cannot draw a polyline because there are no points or only single point return false; } polylineOptions.zIndex(POLYLINE_Z_INDEX); Path path = getPathWithUuid(uuid); // if path does not exist, create it if(path==null) { path = new Path(uuid); pathVsPolylinesMap.put(path,new ArrayList<Polyline>()); } // add polyline path.addPolyline(polylineOptions); // get all polyline objects already drawn on Google Maps List<Polyline> polylines = pathVsPolylinesMap.get(path); // add to Google Maps the new polyline described by the given poliylineOptions object Polyline polyline = addPolylineToGoogleMap(polylineOptions); // add newly added polyline object to the list polylines.add(polyline); // update the mapping pathVsPolylinesMap.put(path,polylines); return true; }
/** * * @param path */ private void removePolylinesForPath(Path path) { List<Polyline> polylines = pathVsPolylinesMap.get(path); Iterator<Polyline> iterator = polylines.iterator(); while(iterator.hasNext()) { Polyline polyline = iterator.next(); polyline.remove(); iterator.remove(); } }
/** * Convert a list of {@link Polyline} to a {@link MultiLineString} * * @param polylineList * @param hasZ * @param hasM * @return */ 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; }
/** * Convert a list of {@link Polyline} to a {@link CompoundCurve} * * @param polylineList * @param hasZ * @param hasM * @return */ 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; }
/** * Add a list of Polylines to the map * * @param map * @param polylines * @return */ 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()); } Polyline polyline = addPolylineToMap(map, polylineOption); multiPolyline.add(polyline); } return multiPolyline; }
/** * Helper function to remove all polylines * * @param polylineArrayList */ public void removePolylines(ArrayList<Polyline> polylineArrayList) { if (polylineArrayList.size() != 0) { for (Polyline polyline : polylineArrayList) { polyline.remove(); } } }