use of com.google.android.gms.maps.model.PolylineOptions in project Android-GoogleDirectionAndPlaceLibrary by akexorcist.
the class GoogleDirection method getPolyline.
public PolylineOptions getPolyline(Document doc, int width, int color) {
ArrayList<LatLng> arr_pos = getDirection(doc);
PolylineOptions rectLine = new PolylineOptions().width(dpToPx(width)).color(color);
for (int i = 0; i < arr_pos.size(); i++) rectLine.add(arr_pos.get(i));
return rectLine;
}
use of com.google.android.gms.maps.model.PolylineOptions in project android-maps-utils by googlemaps.
the class PolySimplifyDemoActivity method startDemo.
@Override
protected void startDemo() {
GoogleMap mMap = getMap();
// Original line
List<LatLng> line = PolyUtil.decode(LINE);
mMap.addPolyline(new PolylineOptions().addAll(line).color(Color.BLACK));
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15));
List<LatLng> simplifiedLine;
/**
* Simplified lines - increasing the tolerance will result in fewer points in the simplified
* line
*/
// meters
double tolerance = 5;
simplifiedLine = PolyUtil.simplify(line, tolerance);
mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.RED - ALPHA_ADJUSTMENT));
// meters
tolerance = 20;
simplifiedLine = PolyUtil.simplify(line, tolerance);
mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.GREEN - ALPHA_ADJUSTMENT));
// meters
tolerance = 50;
simplifiedLine = PolyUtil.simplify(line, tolerance);
mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.MAGENTA - ALPHA_ADJUSTMENT));
// meters
tolerance = 500;
simplifiedLine = PolyUtil.simplify(line, tolerance);
mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.YELLOW - ALPHA_ADJUSTMENT));
// meters
tolerance = 1000;
simplifiedLine = PolyUtil.simplify(line, tolerance);
mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.BLUE - ALPHA_ADJUSTMENT));
// Triangle polygon - the polygon should be closed
ArrayList<LatLng> triangle = new ArrayList<>();
// Should match last point
triangle.add(new LatLng(28.06025, -82.41030));
triangle.add(new LatLng(28.06129, -82.40945));
triangle.add(new LatLng(28.06206, -82.40917));
triangle.add(new LatLng(28.06125, -82.40850));
triangle.add(new LatLng(28.06035, -82.40834));
triangle.add(new LatLng(28.06038, -82.40924));
// Should match first point
triangle.add(new LatLng(28.06025, -82.41030));
mMap.addPolygon(new PolygonOptions().addAll(triangle).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
// Simplified triangle polygon
// meters
tolerance = 88;
List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance);
mMap.addPolygon(new PolygonOptions().addAll(simplifiedTriangle).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
// Oval polygon - the polygon should be closed
List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
mMap.addPolygon(new PolygonOptions().addAll(oval).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
// Simplified oval polygon
// meters
tolerance = 10;
List simplifiedOval = PolyUtil.simplify(oval, tolerance);
mMap.addPolygon(new PolygonOptions().addAll(simplifiedOval).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
}
use of com.google.android.gms.maps.model.PolylineOptions in project Space-Station-Tracker by Kiarasht.
the class MapsActivity method updatePolyline.
/**
* Update polyline sets the future predictions of ISS's position for up to 90 minutes.
*/
private void updatePolyline(Date currentDate) {
long currentLong = currentDate.getTime() / 1000;
final long[] futureTen = new long[10];
for (int i = 0; i < futureTen.length; ++i) {
futureTen[i] = currentLong + (30 * mPoly++);
}
final StringBuilder urlBuilder = new StringBuilder();
for (long aFutureTen : futureTen) {
urlBuilder.append(aFutureTen).append(",");
}
urlBuilder.setLength(urlBuilder.length() - 1);
//TODO: As a user, I would like the option of changing the units from metric to imperial
final String units = "miles";
final String url = "https://api.wheretheiss.at/v1/satellites/25544/positions?timestamps=" + urlBuilder.toString() + "&units=" + units;
final int finalStart = mPoly;
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
final LatLng[] latLngs = new LatLng[10];
for (int i = 0; i < response.length(); ++i) {
latLngs[i] = new LatLng(response.getJSONObject(i).getDouble("latitude"), response.getJSONObject(i).getDouble("longitude"));
}
MapsActivity.this.runOnUiThread(new Runnable() {
public void run() {
if (finalStart == 10) {
for (int i = 0; i < futureTen.length - 1; ++i) {
mPolyLine = mMap.addPolyline(new PolylineOptions().add(latLngs[i], latLngs[i + 1]).width(mCurrentWidth).color(mCurrentColor));
mPolyArray[mPolyCounter++] = mPolyLine;
}
mLast = latLngs[latLngs.length - 1];
++mProgress;
} else {
mPolyArray[mPolyCounter++] = mMap.addPolyline(new PolylineOptions().add(mLast, latLngs[0]).width(mCurrentWidth).color(mCurrentColor));
for (int i = 0; i < futureTen.length - 1; ++i) {
mPolyArray[mPolyCounter++] = mMap.addPolyline(new PolylineOptions().add(latLngs[i], latLngs[i + 1]).width(mCurrentWidth).color(mCurrentColor));
}
mLast = latLngs[latLngs.length - 1];
++mProgress;
}
}
});
} catch (Exception e) {
if (mLast == null) {
FirebaseCrash.report(new Exception("mLast was null"));
}
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError e) {
}
});
mRequestQueue.add(jsonArrayRequest);
}
use of com.google.android.gms.maps.model.PolylineOptions in project cw-omnibus by commonsguy.
the class MainActivity method onMapReady.
@Override
public void onMapReady(final GoogleMap map) {
if (needsInit) {
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044, -73.98180484771729));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);
map.moveCamera(center);
map.animateCamera(zoom);
}
addMarker(map, 40.748963847316034, -73.96807193756104, R.string.un, R.string.united_nations);
addMarker(map, 40.76866299974387, -73.98268461227417, R.string.lincoln_center, R.string.lincoln_center_snippet);
addMarker(map, 40.765136435316755, -73.97989511489868, R.string.carnegie_hall, R.string.practice_x3);
addMarker(map, 40.70686417491799, -74.01572942733765, R.string.downtown_club, R.string.heisman_trophy);
PolylineOptions line = new PolylineOptions().add(new LatLng(40.70686417491799, -74.01572942733765), new LatLng(40.76866299974387, -73.98268461227417), new LatLng(40.765136435316755, -73.97989511489868), new LatLng(40.748963847316034, -73.96807193756104)).width(5).color(Color.RED);
map.addPolyline(line);
PolygonOptions area = new PolygonOptions().add(new LatLng(40.748429, -73.984573), new LatLng(40.753393, -73.996311), new LatLng(40.758393, -73.992705), new LatLng(40.753484, -73.980882)).strokeColor(Color.BLUE);
map.addPolygon(area);
map.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));
map.setOnInfoWindowClickListener(this);
}
use of com.google.android.gms.maps.model.PolylineOptions in project android-maps-utils by googlemaps.
the class Renderer method addKmlPlacemarkToMap.
/**
* Adds a single geometry object to the map with its specified style (used for KML)
*
* @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
*/
protected Object addKmlPlacemarkToMap(KmlPlacemark placemark, Geometry geometry, KmlStyle style, KmlStyle inlineStyle, boolean isVisible) {
String geometryType = geometry.getGeometryType();
boolean hasDrawOrder = placemark.hasProperty("drawOrder");
float drawOrder = 0;
if (hasDrawOrder) {
try {
drawOrder = Float.parseFloat(placemark.getProperty("drawOrder"));
} catch (NumberFormatException e) {
hasDrawOrder = false;
}
}
switch(geometryType) {
case "Point":
MarkerOptions markerOptions = style.getMarkerOptions();
if (inlineStyle != null) {
setInlinePointStyle(markerOptions, inlineStyle, style.getIconUrl());
} else if (style.getIconUrl() != null) {
// Use shared style
addMarkerIcons(style.getIconUrl(), markerOptions);
}
Marker marker = addPointToMap(markerOptions, (KmlPoint) geometry);
marker.setVisible(isVisible);
setMarkerInfoWindow(style, marker, placemark);
if (hasDrawOrder) {
marker.setZIndex(drawOrder);
}
return marker;
case "LineString":
PolylineOptions polylineOptions = style.getPolylineOptions();
if (inlineStyle != null) {
setInlineLineStringStyle(polylineOptions, inlineStyle);
} else if (style.isLineRandomColorMode()) {
polylineOptions.color(KmlStyle.computeRandomColor(polylineOptions.getColor()));
}
Polyline polyline = addLineStringToMap(polylineOptions, (LineString) geometry);
polyline.setVisible(isVisible);
if (hasDrawOrder) {
polyline.setZIndex(drawOrder);
}
return polyline;
case "Polygon":
PolygonOptions polygonOptions = style.getPolygonOptions();
if (inlineStyle != null) {
setInlinePolygonStyle(polygonOptions, inlineStyle);
} else if (style.isPolyRandomColorMode()) {
polygonOptions.fillColor(KmlStyle.computeRandomColor(polygonOptions.getFillColor()));
}
Polygon polygon = addPolygonToMap(polygonOptions, (DataPolygon) geometry);
polygon.setVisible(isVisible);
if (hasDrawOrder) {
polygon.setZIndex(drawOrder);
}
return polygon;
case "MultiGeometry":
return addMultiGeometryToMap(placemark, (KmlMultiGeometry) geometry, style, inlineStyle, isVisible);
}
return null;
}
Aggregations