/** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; if(checkingStation) { updateMap(mMap,stationPos); mMap.moveCamera(CameraUpdateFactory.newLatLng(stationPos)); mMap.moveCamera(CameraUpdateFactory.zoomTo(15)); } else { try { PolylineOptions mPolyOpt = getFromJSONArray(track); updateMap(mMap,mPolyOpt); mMap.moveCamera(CameraUpdateFactory.newLatLng(mPolyOpt.getPoints().get(0))); mMap.moveCamera(CameraUpdateFactory.zoomTo(15)); } catch (JSONException e) { e.printStackTrace(); } } }
/** * 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); }
@Override public void onDirectionFinderSuccess(List<Route> routes, Route routeObject) { callProgressDialog(); polylinePaths = new ArrayList<>(); if (!routes.isEmpty()) { for (Route route : routes) { PolylineOptions polylineOptions = new PolylineOptions(). color(Color.BLUE). width(5); for (int i = 0; i < route.getPoints().size(); i++) polylineOptions.add(route.getPoints().get(i)); polylinePaths.add(googleMap.addPolyline(polylineOptions)); } //It allows to know to the Fragment that there is a new Route placesListener.onLocationsChange(routeObject); } else Toast.makeText(this, "There is no results", Toast.LENGTH_SHORT).show(); }
static PolylineOptions trk2TrkOpts(Track trk) { List<TrackPoint> trkPts = new ArrayList<>(); for (TrackSegment seg : trk.getTrackSegments()) { trkPts.addAll(seg.getTrackPoints()); } PolylineOptions pos = PolylilneStyle.getDefaultStyle(); for (TrackPoint trkPt : trkPts) { LatLng latLng = new LatLng(trkPt.getLatitude(), trkPt.getLongitude()); pos.add(latLng); } return pos; }
@Override public void onParserTaskfinish(LatLng startCoordinate, LatLng endCoordinate, PolylineOptions lineOptions, List<Location> locations) { planningDialog.dismiss(); Intent navigationActivity = new Intent(getBaseContext(), NavigationActivity.class); navigationActivity.putExtra(NavigationActivity.START_COORDINATE_EXTRA, startCoordinate); navigationActivity.putExtra(NavigationActivity.END_COORDINATE_EXTRA, endCoordinate); navigationActivity.putExtra(NavigationActivity.POLY_LINE_OPTIONS_EXTRA, lineOptions); if(locations == null){ Log.d("Intent","failed"); } else{ Log.d("Intent","success"); Gson gson = new Gson(); Type type = new TypeToken<List<Location>>() {}.getType(); String json = gson.toJson(locations, type); Log.d("Intent",json); Log.d("Location Count",Integer.toString(locations.size())); navigationActivity.putExtra(NavigationActivity.ADDITIONAL_LOCATION_EXTRA, json); } startActivity(navigationActivity); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); }
/** * Constructor of the class * * @param googleMap a google map * @param trackColor the color of the track */ public MapHandler(GoogleMap googleMap, int trackColor) { if (googleMap == null) { throw new IllegalArgumentException(); } this.trackColor = trackColor; this.googleMap = googleMap; this.googleMap.setLocationSource(null); uiSettings = this.googleMap.getUiSettings(); uiSettings.setMyLocationButtonEnabled(false); uiSettings.setCompassEnabled(false); polylineOptions = new PolylineOptions(); }
/** * Convert a {@link LineString} to a {@link PolylineOptions} * * @param lineString * @return */ 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; }
/** * 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; }
/** * Add a MultiPolylineOptions to the map as markers * * @param shapeMarkers * @param map * @param multiPolyline * @param polylineMarkerOptions * @param globalPolylineOptions * @return */ public MultiPolylineMarkers addMultiPolylineToMapAsMarkers( GoogleMapShapeMarkers shapeMarkers, GoogleMap map, MultiPolylineOptions multiPolyline, MarkerOptions polylineMarkerOptions, PolylineOptions globalPolylineOptions) { MultiPolylineMarkers polylines = new MultiPolylineMarkers(); for (PolylineOptions polylineOptions : multiPolyline .getPolylineOptions()) { PolylineMarkers polylineMarker = addPolylineToMapAsMarkers(map, polylineOptions, polylineMarkerOptions, globalPolylineOptions); shapeMarkers.add(polylineMarker); polylines.add(polylineMarker); } return polylines; }
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); }
public static void drawSubsection(GoogleMap map, List<LatLng> coords, int startIndex, int endIndex, int color){ if(sectionPolyline != null){ sectionPolyline.remove(); } PolylineOptions line = new PolylineOptions(); line.geodesic(true); line.width(14); line.zIndex(100); line.color(color); int start = startIndex; int end = endIndex; if(startIndex > endIndex){ int temp = startIndex; start = endIndex; end = temp; } for(LatLng ll : coords.subList(start, end)){ line.add(ll); } sectionPolyline = map.addPolyline(line); }
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; int marca = 0; for (Punto incidencia :incidencias) { mMap.addMarker(new MarkerOptions().position(new LatLng(incidencia.getX(), incidencia.getY())).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET))); } for (Punto punto : puntos) { mMap.addMarker(new MarkerOptions().position(new LatLng(punto.getX(), punto.getY())).title("Step " + (++marca))); } mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(puntos.get(0).getX(), puntos.get(0).getY()))); UiSettings ui = mMap.getUiSettings(); ui.setZoomControlsEnabled(true); for (int i = 0; i < puntos.size() - 1; i++) { PolylineOptions linea = new PolylineOptions().add(new LatLng(puntos.get(i).getX(), puntos.get(i).getY())).add(new LatLng(puntos.get(i + 1).getX(), puntos.get(i + 1).getY())); linea.color(Color.BLUE); linea.width(3f); mMap.addPolyline(linea); } }
/** * 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; }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == NAVIGATION_REQUEST_CODE) { stopService(LocService); EventoLocalizacion actual; ArrayList<LatLng> localizaciones = new ArrayList<>(); for (int i = 0; i < listaLocalizaciones.size(); i++) { actual = listaLocalizaciones.get(i); mapa.addMarker(new MarkerOptions().title("Punto " + Integer.toString(i) + " " + actual.tiempo).position(actual.localizacion)); localizaciones.add(actual.localizacion); } mapa.addPolyline(new PolylineOptions().addAll(localizaciones).color(Color.RED)); mapa.moveCamera(CameraUpdateFactory.newLatLngZoom(localizaciones.get(localizaciones.size() - 1), 15)); } }
@Override public void run(){ Location location = activity.lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); double latitude = location.getLatitude(); double longitude = location.getLongitude(); final LatLng currentPos = new LatLng(latitude, longitude); activity.myRecord.add(currentPos); activity.runOnUiThread(new Runnable(){ @Override public void run(){ activity.mMap.addPolyline(new PolylineOptions() .add(currentPos) .width(12) .color(Color.parseColor("#05b1fb")) .geodesic(true)); } }); Log.d("RECORDING", String.valueOf(activity.myRecord)); }
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; }
public void setPolyline(Polyline newPolyline){ if (oldPolyline != null){ oldPolyline.remove(); } if (newPolyline == null){ return; } PolylineOptions options = new PolylineOptions() .color(newPolyline.getColor()) .visible(newPolyline.isVisible()) .width(newPolyline.getWidth()) ; for (GeoPoint p : newPolyline.getPoints()){ options.add(new LatLng(p.getLatitude(), p.getLongitude())); } oldPolyline = map.addPolyline(options); }
/** * Reconstructs the result. * * @param in The parcel where the result was written to */ protected Result(Parcel in) { bundleId = in.readString(); markers = new ArrayList<>(); ArrayList<MarkerOptions> optionsList = in.createTypedArrayList(MarkerOptions.CREATOR); ArrayList<Bitmap> bitmapList = in.createTypedArrayList(Bitmap.CREATOR); ArrayList<Pair<MarkerOptions, Bitmap>> markers = new ArrayList<>(); polylines = in.createTypedArrayList(PolylineOptions.CREATOR); polygons = in.createTypedArrayList(PolygonOptions.CREATOR); circles = in.createTypedArrayList(CircleOptions.CREATOR); if (bitmapList.size() != optionsList.size()){ throw new RuntimeException("optionlist and bitmapList are not equal in size"); } for (int i = 0; i < optionsList.size(); i++){ markers.add(new Pair<MarkerOptions, Bitmap>(optionsList.get(i),bitmapList.get(i))); } this.markers = markers; }
@Override public void addFlightPathPoint(final LatLongAlt coord) { final LatLng position = MapUtils.coordToLatLng(coord); getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { if (showFlightPath) { if (flightPath == null) { PolylineOptions flightPathOptions = new PolylineOptions(); flightPathOptions.color(FLIGHT_PATH_DEFAULT_COLOR) .width(FLIGHT_PATH_DEFAULT_WIDTH).zIndex(1); flightPath = googleMap.addPolyline(flightPathOptions); } List<LatLng> oldFlightPath = flightPath.getPoints(); oldFlightPath.add(position); flightPath.setPoints(oldFlightPath); } } }); }
@Override public void updateDroneLeashPath(PathSource pathSource) { List<LatLong> pathCoords = pathSource.getPathPoints(); final List<LatLng> pathPoints = new ArrayList<LatLng>(pathCoords.size()); for (LatLong coord : pathCoords) { pathPoints.add(MapUtils.coordToLatLng(coord)); } if (mDroneLeashPath == null) { final PolylineOptions flightPath = new PolylineOptions(); flightPath.color(DRONE_LEASH_DEFAULT_COLOR).width( MapUtils.scaleDpToPixels(DRONE_LEASH_DEFAULT_WIDTH, getResources())); getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { mDroneLeashPath = getMap().addPolyline(flightPath); mDroneLeashPath.setPoints(pathPoints); } }); } else { mDroneLeashPath.setPoints(pathPoints); } }
@Override public void updateMissionPath(PathSource pathSource) { List<LatLong> pathCoords = pathSource.getPathPoints(); final List<LatLng> pathPoints = new ArrayList<>(pathCoords.size()); for (LatLong coord : pathCoords) { pathPoints.add(MapUtils.coordToLatLng(coord)); } if (missionPath == null) { final PolylineOptions pathOptions = new PolylineOptions(); pathOptions.color(MISSION_PATH_DEFAULT_COLOR).width(MISSION_PATH_DEFAULT_WIDTH); getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { missionPath = getMap().addPolyline(pathOptions); missionPath.setPoints(pathPoints); } }); } else { missionPath.setPoints(pathPoints); } }
@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); } }
/** * 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(); }
/** * Adds the route to the map. * * @param googleMap the map * @param routeMapInfo the view model containing the information for the route */ public void addRouteToMap(final GoogleMap googleMap, final RouteMapData routeMapInfo) { final LatLngBounds.Builder latLngBounds = new LatLngBounds.Builder(); for (PolylineData polylineData : routeMapInfo.getPolylineDataList()) { PolylineOptions polyline = getPolylineOptions(latLngBounds, polylineData); if (polyline != null) { googleMap.addPolyline(polyline); } } googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() { @Override public void onMapLoaded() { addMarker(routeMapInfo.getStartPoint(), googleMap); addMarker(routeMapInfo.getEndPoint(), googleMap); googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds.build(), 200)); } }); }
@Test public void shouldAddRouteToMap() { // given RouteMapData routeMapData = prepareRouteMapData(); doAnswer(mapLoadedCallbackAnswer).when(googleMap).setOnMapLoadedCallback(any(GoogleMap.OnMapLoadedCallback.class)); doAnswer(newLatLngBoundsAnswer).when(googleMap).addPolyline(any(PolylineOptions.class)); when(CameraUpdateFactory.newLatLngBounds(any(LatLngBounds.class), anyInt())).thenReturn(cameraUpdate); // when routeMapService.addRouteToMap(googleMap, routeMapData); // then verify(googleMap, times(1)).addPolyline(any(PolylineOptions.class)); verify(googleMap, times(2)).addMarker(any(MarkerOptions.class)); verify(googleMap, times(1)).animateCamera(any(CameraUpdate.class)); }
/** 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); } } }
@Override protected PolylineOptions doInBackground(TripData... trips) { trip = trips[0]; // always get just the first trip List<LatLng> pos = trip.getPoints(); ShowMap.this.gpsoptions = new PolylineOptions(); ShowMap.this.gpsoptions.addAll(pos); ShowMap.this.markers = new ArrayList<MarkerOptions>(pos.size()); List<String> timesAcc = trip.getTimesAcc(); // use custom icon for trip points Bitmap bmp = Bitmap.createBitmap(2, 2, Bitmap.Config.ALPHA_8); for (int i = timesAcc.size(); i-->0;) { markers.add(new MarkerOptions() .position(pos.get(i)) .title("trip point") .snippet(timesAcc.get(i)) .icon(BitmapDescriptorFactory.fromBitmap(bmp))); } return ShowMap.this.gpsoptions; }
private void displayLinesAndAreas(List<ILatLonRecord> waypoints) { try { PolylineOptions polyline = new PolylineOptions().width(ResourcesHelper.getDimensionPixelSize(this, R.dimen.task_line_width)).color(getResources().getColor(R.color.task_line)); for (int i = 0; i < waypoints.size(); i++) { CRecordWayPoint cRecordWayPoint = (CRecordWayPoint) waypoints.get(i); if (cRecordWayPoint.getType() == CRecordType.START || cRecordWayPoint.getType() == CRecordType.TURN || cRecordWayPoint.getType() == CRecordType.FINISH) { polyline.add(new LatLng(waypoints.get(i).getLatLon().getLat(), waypoints.get(i).getLatLon().getLon())); } if (cRecordWayPoint.getType() == CRecordType.TURN) { googleMap.addCircle(new CircleOptions().center(new LatLng(waypoints.get(i).getLatLon().getLat(), waypoints.get(i).getLatLon().getLon())) .radius(TaskConfig.getAreaWidth()).strokeColor(Color.TRANSPARENT) .strokeWidth(getResources().getDimensionPixelSize(R.dimen.task_line_width)) .fillColor(getResources().getColor(R.color.task_fill_color))); } } googleMap.addPolyline(polyline); } catch (Throwable t) { Logger.logError("Error trying to draw waypoints: " + t.getMessage()); } }
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(); }
@Override public void onMapReady(GoogleMap googleMap) { //Creamos una localizacion LatLng lugar = new LatLng(19.3910038, -99.2837004);//creamos el punto de partida(DF) //Movemos la camara,El metodo newLatLngZoom esta sobrecargado //Este es uno de los metodos,y recibe una localizacion y el respectivo zoom como segundo parametro googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(lugar, 20)); // Indicamos los puntos para crear la polilinea //Ente este caso la ruta es del df - Guerrero - Michoacan y llegando a Guadalajara googleMap.addPolyline(new PolylineOptions().geodesic(true) .add(new LatLng(17.547789, -99.532435)) // Guerrero .add(new LatLng(19.1539267, -103.0220045)) // Michoacan .add(new LatLng(20.6998812, -103.405454)) // Guadalajara ); //Utilidad para generar polilineas de google //https://developers.google.com/maps/documentation/utilities/polylineutility }
@Override protected void onPostExecute(List<SnappedPoint> snappedPoints) { mSnappedPoints = snappedPoints; mProgressBar.setVisibility(View.INVISIBLE); findViewById(R.id.speed_limits).setEnabled(true); com.google.android.gms.maps.model.LatLng[] mapPoints = new com.google.android.gms.maps.model.LatLng[mSnappedPoints.size()]; int i = 0; LatLngBounds.Builder bounds = new LatLngBounds.Builder(); for (SnappedPoint point : mSnappedPoints) { mapPoints[i] = new com.google.android.gms.maps.model.LatLng(point.location.lat, point.location.lng); bounds.include(mapPoints[i]); i += 1; } mMap.addPolyline(new PolylineOptions().add(mapPoints).color(Color.BLUE)); mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 0)); }
/** * 形状を追加する。 * * @param shapeOptions 形状オプション */ private void addShapes(@NonNull List<Parcelable> shapeOptions) { if (mMap == null) { return; } for (final Parcelable shapeOption : shapeOptions) { if (shapeOption instanceof PolygonOptions) { mShapes.add(mMap.addPolygon((PolygonOptions) shapeOption)); } else if (shapeOption instanceof PolylineOptions) { mShapes.add(mMap.addPolyline((PolylineOptions) shapeOption)); } else if (shapeOption instanceof CircleOptions) { mShapes.add(mMap.addCircle((CircleOptions) shapeOption)); } else { Log.w(TAG, "想定していない形状。" + shapeOption.getClass().getSimpleName()); } } }
protected void onPostExecute(String file_url) { if (polyz != null) for (int i = 0; i < polyz.size() - 1; i++) { LatLng src = polyz.get(i); LatLng dest = polyz.get(i + 1); line = new PolylineOptions() .add(new LatLng(src.latitude, src.longitude), new LatLng(dest.latitude, dest.longitude)) .width(8).color(Color.BLUE).geodesic(true); onPolyInit(line); } pDialog.dismiss(); }
@Override public PolylineOptions getPath(LatLng start, LatLng finish) { // computes all possible paths from starting vertex computePaths(latLngNodeMap.get(start)); // holds a list of vertices that make up the shortest path between start and finish List <Vertex> path = getShortestPathTo(latLngNodeMap.get(finish)); PolylineOptions options = new PolylineOptions(); // add the LatLngs of each vertex in the path to the polyline for (int i = 0; i < path.size(); i++) { LatLng cords = new LatLng(path.get(i).lat, path.get(i).lon); options.add(cords); } options.color(Color.BLUE); return options; }
public PolylineOptions getPath (String start, String finish) { // computes all possible paths from starting vertex computePaths(nodeMap.get(start)); // holds a list of vertices that make up the shortest path between start and finish List <Vertex> path = getShortestPathTo(nodeMap.get(finish)); PolylineOptions options = new PolylineOptions(); // add the LatLngs of each vertex in the path to the polyline for (int i = 0; i < path.size(); i++) { LatLng cords = new LatLng(path.get(i).lat, path.get(i).lon); options.add(cords); } options.color(Color.BLUE); return options; }
public void updateMapDraw(objData objDataList) { Log.v(TAG, "map Update!"); if (current == null) { map.addMarker(new MarkerOptions() .position(objDataList.myLatlng) .title("Start") ); Log.v(TAG, "Added init marker"); current = objDataList; } else { //add a new line to map map.addPolyline(new PolylineOptions() .add(current.myLatlng,objDataList.myLatlng) //line segment. .color(getActivityColor(objDataList.act)) //make it red. .clickable(true) //for the listener. //.width(10) //width of 10 ); //move the camera to center it to it. map.moveCamera(CameraUpdateFactory.newLatLng(objDataList.myLatlng)); //and finally make it the current position current = objDataList; } }
@Override public void onMapReady(GoogleMap googleMap) { PolylineOptions polyOptions = new PolylineOptions(); List<String[]> result = SQLDBController.getInstance().query("SELECT attr_time, attr_lat, attr_lng FROM " + SQLTableName.PREFIX + DeviceID.get(this.context) + SQLTableName.GPS + " WHERE attr_time > ? AND attr_time < ?", new String[]{ String.valueOf(this.start), String.valueOf(this.end) }, false); LatLng pos = null; for(String[] row : result) { pos = new LatLng(Float.valueOf(row[1]), Float.valueOf(row[2])); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); polyOptions.add(pos); positionMarkers.add(googleMap.addMarker(new MarkerOptions().title(sdf.format(new Date(Long.valueOf(row[0])))).position(pos))); } if(pos == null) { return; } polyline = googleMap.addPolyline(polyOptions); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(pos, 15)); }
protected void drawPolyline(List<Location> locationList) { // add polyline to map + calculate bounding box googleMap.clear(); PolylineOptions polylineOptions = new PolylineOptions(); LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); for (Location location : locationList) { LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); polylineOptions.add(latLng); boundsBuilder.include(latLng); } googleMap.addPolyline(polylineOptions .width(5) .color(Color.BLUE)); int padding = (int) getResources().getDimension(R.dimen.map_bounds_padding); googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(boundsBuilder.build(), padding)); }