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

The following examples show how to use com.google.android.gms.maps.model.PolylineOptions. 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: MainActivity.java    From ExamplesAndroid with Apache License 2.0 6 votes vote down vote up
@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
}
 
Example #2
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options.
 *
 * @param context      A context.
 * @param locationList A list of latitude and longitude.
 * @param width        Width of the polyline in screen pixels.
 * @param color        Color of the polyline as a 32-bit ARGB color.
 * @param clickable    Is polyline clickable.
 * @param jointType    Joint type for all vertices of the polyline except the start and end vertices.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static PolylineOptions createPolyline(
        @NonNull Context context,
        @Nullable ArrayList<LatLng> locationList,
        @Dimension(unit = Dimension.DP) int width,
        @ColorInt int color,
        boolean clickable,
        int jointType
) {
    return createPolyline(
            context,
            locationList,
            width,
            color,
            clickable,
            jointType,
            null,
            null,
            null
    );
}
 
Example #3
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options in transit mode.
 *
 * @param context      A context.
 * @param stepList     A list of latitude and longitude for the steps.
 * @param transitWidth Width of the polyline in screen pixels for transit polyline.
 * @param transitColor Color of the polyline as a 32-bit ARGB color for transit polyline.
 * @param walkingWidth Width of the polyline in screen pixels for walking polyline.
 * @param walkingColor Color of the polyline as a 32-bit ARGB color for walking polyline.
 * @param clickable    Is polyline clickable.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static ArrayList<PolylineOptions> createTransitPolyline(
        @NonNull Context context,
        @Nullable List<Step> stepList,
        @Dimension(unit = Dimension.DP) int transitWidth,
        @ColorInt int transitColor,
        @Dimension(unit = Dimension.DP) int walkingWidth,
        @ColorInt int walkingColor,
        boolean clickable) {
    return createTransitPolyline(
            context,
            stepList,
            transitWidth,
            transitColor,
            null,
            walkingWidth,
            walkingColor,
            null,
            clickable,
            JointType.DEFAULT,
            null,
            null
    );
}
 
Example #4
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options.
 *
 * @param context         A context.
 * @param locationList    A list of latitude and longitude.
 * @param width           Width of the polyline in screen pixels.
 * @param color           Color of the polyline as a 32-bit ARGB color.
 * @param clickable       Is polyline clickable.
 * @param patternItemList Stroke pattern for the polyline.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static PolylineOptions createPolyline(
        @NonNull Context context,
        @Nullable ArrayList<LatLng> locationList,
        @Dimension(unit = Dimension.DP) int width,
        @ColorInt int color,
        boolean clickable,
        @Nullable List<PatternItem> patternItemList
) {
    return createPolyline(
            context,
            locationList,
            width,
            color,
            clickable,
            JointType.DEFAULT,
            null,
            null,
            patternItemList
    );
}
 
Example #5
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Convert a {@link LineString} to a {@link PolylineOptions}
 *
 * @param lineString line string
 * @return polyline options
 */
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;
}
 
Example #6
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options in transit mode.
 *
 * @param context                A context.
 * @param stepList               A list of latitude and longitude for the steps.
 * @param transitWidth           Width of the polyline in screen pixels for transit polyline.
 * @param transitColor           Color of the polyline as a 32-bit ARGB color for transit polyline.
 * @param transitPatternItemList Stroke pattern for the polyline for transit polyline.
 * @param walkingWidth           Width of the polyline in screen pixels for walking polyline.
 * @param walkingColor           Color of the polyline as a 32-bit ARGB color for walking polyline.
 * @param walkingPatternItemList Stroke pattern for the polyline for walking polyline.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static ArrayList<PolylineOptions> createTransitPolyline(
        @NonNull Context context,
        @Nullable List<Step> stepList,
        @Dimension(unit = Dimension.DP) int transitWidth,
        @Nullable List<PatternItem> transitPatternItemList,
        @ColorInt int transitColor,
        @Dimension(unit = Dimension.DP) int walkingWidth,
        @ColorInt int walkingColor,
        @Nullable List<PatternItem> walkingPatternItemList) {
    return createTransitPolyline(
            context,
            stepList,
            transitWidth,
            transitColor,
            transitPatternItemList,
            walkingWidth,
            walkingColor,
            walkingPatternItemList,
            true,
            JointType.DEFAULT,
            null,
            null
    );
}
 
Example #7
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options.
 *
 * @param context      A context.
 * @param locationList A list of latitude and longitude.
 * @param width        Width of the polyline in screen pixels.
 * @param color        Color of the polyline as a 32-bit ARGB color.
 * @param clickable    Is polyline clickable.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static PolylineOptions createPolyline(
        @NonNull Context context,
        @Nullable ArrayList<LatLng> locationList,
        @Dimension(unit = Dimension.DP) int width,
        @ColorInt int color,
        boolean clickable
) {
    return createPolyline(
            context,
            locationList,
            width,
            color,
            clickable,
            JointType.DEFAULT,
            null,
            null,
            null
    );
}
 
Example #8
Source File: MainActivity.java    From roads-api-samples with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #9
Source File: DistanceAction.java    From Companion-For-PUBG-Android with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #10
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options.
 *
 * @param context      A context.
 * @param locationList A list of latitude and longitude.
 * @param width        Width of the polyline in screen pixels.
 * @param color        Color of the polyline as a 32-bit ARGB color.
 * @return Options for a polyline.
 * @since 1.0.0
 */
public static PolylineOptions createPolyline(
        @NonNull Context context,
        @Nullable ArrayList<LatLng> locationList,
        @Dimension(unit = Dimension.DP) int width,
        @ColorInt int color
) {
    return createPolyline(
            context,
            locationList,
            width,
            color,
            true,
            JointType.DEFAULT,
            null,
            null,
            null
    );
}
 
Example #11
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 #12
Source File: MapUtils.java    From ridesharing-android with MIT License 6 votes vote down vote up
public static GoogleMapConfig.Builder getBuilder(Context context) {
    int width = context.getResources().getDisplayMetrics().widthPixels;
    int height = context.getResources().getDisplayMetrics().heightPixels;
    int mapRouteWidth = context.getResources().getDimensionPixelSize(R.dimen.map_route_width);
    GoogleMapConfig.TripOptions tripOptions = GoogleMapConfig.newTripOptions()
            .tripDestinationMarker(new MarkerOptions()
                    .anchor(0.5f, 0.5f)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_destination_marker)))
            .tripPassedRoutePolyline(null)
            .tripComingRoutePolyline(new PolylineOptions()
                    .width(mapRouteWidth)
                    .color(Color.BLACK)
                    .pattern(Collections.<PatternItem>singletonList(new Dash(mapRouteWidth))));
    return GoogleMapConfig.newBuilder(context)
            .tripOptions(tripOptions)
            .boundingBoxDimensions(width, height / 3);
}
 
Example #13
Source File: DistanceDemoActivity.java    From android-maps-utils with Apache License 2.0 6 votes vote down vote up
@Override
protected void startDemo(boolean isRestore) {
    mTextView = findViewById(R.id.textView);

    if (!isRestore) {
        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();
}
 
Example #14
Source File: GglMapAiPoint2PointManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void drawPointLine(LatLng latLngDevice) {
    if (this.pointMarker != null) {
        LatLng latLng = this.pointMarker.getPosition();
        this.latLngs.clear();
        this.latLngs.add(latLng);
        this.latLngs.add(latLngDevice);
        if (this.polyline == null) {
            PolylineOptions polylineOptions = new PolylineOptions();
            polylineOptions.addAll(this.latLngs);
            polylineOptions.color(this.context.getResources().getColor(R.color.x8_drone_inface_line)).zIndex(50.0f);
            polylineOptions.width(4.0f);
            if (this.polyline != null) {
                this.polyline.remove();
            }
            this.polyline = this.googleMap.addPolyline(polylineOptions);
            this.polyline.setPattern(PATTERN_DASHED);
        }
        this.polyline.setPoints(this.latLngs);
    }
}
 
Example #15
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options in transit mode.
 *
 * @param context      A context.
 * @param stepList     A list of latitude and longitude for the steps.
 * @param transitWidth Width of the polyline in screen pixels for transit polyline.
 * @param transitColor Color of the polyline as a 32-bit ARGB color for transit polyline.
 * @param walkingWidth Width of the polyline in screen pixels for walking polyline.
 * @param walkingColor Color of the polyline as a 32-bit ARGB color for walking polyline.
 * @return Options for a polyline.
 * @since 1.0.0
 */
public static ArrayList<PolylineOptions> createTransitPolyline(
        @NonNull Context context,
        @Nullable List<Step> stepList,
        @Dimension(unit = Dimension.DP) int transitWidth,
        @ColorInt int transitColor,
        @Dimension(unit = Dimension.DP) int walkingWidth,
        @ColorInt int walkingColor) {
    return createTransitPolyline(
            context,
            stepList,
            transitWidth,
            transitColor,
            null,
            walkingWidth,
            walkingColor,
            null,
            true,
            JointType.DEFAULT,
            null,
            null
    );
}
 
Example #16
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the path option to the polyline options.
 *
 * @param context    A context.
 * @param pathOption Path options of the steps.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static PolylineOptions createPolyline(
        @NonNull Context context,
        @NonNull PathOption pathOption
) {
    return createPolyline(
            context,
            pathOption.locationList,
            pathOption.width,
            pathOption.color,
            pathOption.clickable,
            pathOption.jointType,
            pathOption.startCap,
            pathOption.endCap,
            pathOption.patternItemList
    );
}
 
Example #17
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 #18
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options in transit mode.
 *
 * @param context      A context.
 * @param stepList     A list of latitude and longitude for the steps.
 * @param transitWidth Width of the polyline in screen pixels for transit polyline.
 * @param transitColor Color of the polyline as a 32-bit ARGB color for transit polyline.
 * @param walkingWidth Width of the polyline in screen pixels for walking polyline.
 * @param walkingColor Color of the polyline as a 32-bit ARGB color for walking polyline.
 * @param clickable    Is polyline clickable.
 * @param jointType    Joint type for all vertices of the polyline except the start and end vertices.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static ArrayList<PolylineOptions> createTransitPolyline(
        @NonNull Context context,
        @Nullable List<Step> stepList,
        @Dimension(unit = Dimension.DP) int transitWidth,
        @ColorInt int transitColor,
        @Dimension(unit = Dimension.DP) int walkingWidth,
        @ColorInt int walkingColor,
        boolean clickable,
        int jointType) {
    return createTransitPolyline(
            context,
            stepList,
            transitWidth,
            transitColor,
            null,
            walkingWidth,
            walkingColor,
            null,
            clickable,
            jointType,
            null,
            null
    );
}
 
Example #19
Source File: DirectionConverter.java    From GoogleDirectionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the list of latitude and longitude to the polyline options in transit mode.
 *
 * @param context      A context.
 * @param stepList     A list of latitude and longitude for the steps.
 * @param transitWidth Width of the polyline in screen pixels for transit polyline.
 * @param transitColor Color of the polyline as a 32-bit ARGB color for transit polyline.
 * @param walkingWidth Width of the polyline in screen pixels for walking polyline.
 * @param walkingColor Color of the polyline as a 32-bit ARGB color for walking polyline.
 * @param clickable    Is polyline clickable.
 * @param startCap     Cap at the start vertex of the polyline.
 * @param endCap       Cap at the end vertex of the polyline.
 * @return Options for a polyline.
 * @since 1.2.0
 */
public static ArrayList<PolylineOptions> createTransitPolyline(
        @NonNull Context context,
        @Nullable List<Step> stepList,
        @Dimension(unit = Dimension.DP) int transitWidth,
        @ColorInt int transitColor,
        @Dimension(unit = Dimension.DP) int walkingWidth,
        @ColorInt int walkingColor,
        boolean clickable,
        @Nullable Cap startCap,
        @Nullable Cap endCap) {
    return createTransitPolyline(
            context,
            stepList,
            transitWidth,
            transitColor,
            null,
            walkingWidth,
            walkingColor,
            null,
            clickable,
            JointType.DEFAULT,
            startCap,
            endCap
    );
}
 
Example #20
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 #21
Source File: MainActivity.java    From roads-api-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the GPX button-click event, running the demo snippet {@link #loadGpxData}.
 */
public void onGpxButtonClick(View view) {
    try {
        mCapturedLocations = loadGpxData(Xml.newPullParser(),
                getResources().openRawResource(R.raw.gpx_data));
        findViewById(R.id.snap_to_roads).setEnabled(true);

        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        PolylineOptions polyline = new PolylineOptions();

        for (LatLng ll : mCapturedLocations) {
            com.google.android.gms.maps.model.LatLng mapPoint =
                    new com.google.android.gms.maps.model.LatLng(ll.lat, ll.lng);
            builder.include(mapPoint);
            polyline.add(mapPoint);
        }

        mMap.addPolyline(polyline.color(Color.RED));
        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
    } catch (XmlPullParserException | IOException e) {
        e.printStackTrace();
        toastException(e);
    }
}
 
Example #22
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a {@link MultiLineString} to a {@link MultiPolylineOptions}
 *
 * @param multiLineString multi line string
 * @return multi polyline options
 */
public MultiPolylineOptions toPolylines(MultiLineString multiLineString) {

    MultiPolylineOptions polylines = new MultiPolylineOptions();

    for (LineString lineString : multiLineString.getLineStrings()) {
        PolylineOptions polyline = toPolyline(lineString);
        polylines.add(polyline);
    }

    return polylines;
}
 
Example #23
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a {@link CompoundCurve} to a {@link MultiPolylineOptions}
 *
 * @param compoundCurve compound curve
 * @return multi polyline options
 */
public MultiPolylineOptions toPolylines(CompoundCurve compoundCurve) {

    MultiPolylineOptions polylines = new MultiPolylineOptions();

    for (LineString lineString : compoundCurve.getLineStrings()) {
        PolylineOptions polyline = toPolyline(lineString);
        polylines.add(polyline);
    }

    return polylines;
}
 
Example #24
Source File: MapFragment.java    From mirror with Apache License 2.0 5 votes vote down vote up
@Override
public void onRoutingSuccess(ArrayList<Route> routes, int shortestRouteIndex) {
    for (int i = 0; i < routes.size(); i++) {
        //In case of more than 5 alternative routes
        int colorIndex = i % COLORS.length;
        PolylineOptions polyOptions = new PolylineOptions()
                .color(getResources().getColor(COLORS[colorIndex]))
                .width(5 + i)
                .addAll(routes.get(i).getPoints());
        mMap.addPolyline(polyOptions);
    }
}
 
Example #25
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Compare list of line strings with list of polylines
 *
    * @param converter
 * @param lineStrings
 * @param polylines
 */
private static void compareLineStringsAndPolylines(
           GoogleMapShapeConverter converter,
		List<LineString> lineStrings, List<PolylineOptions> polylines) {

	TestCase.assertEquals(lineStrings.size(), polylines.size());
	for (int i = 0; i < lineStrings.size(); i++) {
		compareLineStringAndPolyline(converter, lineStrings.get(i), polylines.get(i));
	}

}
 
Example #26
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Test the LineString conversion
 * 
 * @param converter
 * @param lineString
 */
private static void convertLineString(GoogleMapShapeConverter converter,
		LineString lineString) {

	PolylineOptions polyline = converter.toPolyline(lineString);
	TestCase.assertNotNull(polyline);

	compareLineStringAndPolyline(converter, lineString, polyline);

	LineString lineString2 = converter.toLineString(polyline);
	compareLineStrings(lineString, lineString2);
}
 
Example #27
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a {@link MultiPolylineOptions} to a {@link CompoundCurve}
 *
 * @param multiPolylineOptions multi polyline options
 * @param hasZ                 has z flag
 * @param hasM                 has m flag
 * @return compound curve
 */
public CompoundCurve toCompoundCurveWithOptions(
        MultiPolylineOptions multiPolylineOptions, boolean hasZ,
        boolean hasM) {

    CompoundCurve compoundCurve = new CompoundCurve(hasZ, hasM);

    for (PolylineOptions polyline : multiPolylineOptions
            .getPolylineOptions()) {
        LineString lineString = toLineString(polyline);
        compoundCurve.addLineString(lineString);
    }

    return compoundCurve;
}
 
Example #28
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a {@link MultiPolylineOptions} to a {@link MultiLineString}
 *
 * @param multiPolylineOptions multi polyline options
 * @param hasZ                 has z flag
 * @param hasM                 has m flag
 * @return multi line string
 */
public MultiLineString toMultiLineStringFromOptions(
        MultiPolylineOptions multiPolylineOptions, boolean hasZ,
        boolean hasM) {

    MultiLineString multiLineString = new MultiLineString(hasZ, hasM);

    for (PolylineOptions polyline : multiPolylineOptions
            .getPolylineOptions()) {
        LineString lineString = toLineString(polyline);
        multiLineString.addLineString(lineString);
    }

    return multiLineString;
}
 
Example #29
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the inline linestring style by copying over the styles that have been set
 *
 * @param polylineOptions polygon options object to add inline styles to
 * @param inlineStyle     inline styles to apply
 */
private void setInlineLineStringStyle(PolylineOptions polylineOptions, KmlStyle inlineStyle) {
    PolylineOptions inlinePolylineOptions = inlineStyle.getPolylineOptions();
    if (inlineStyle.isStyleSet("outlineColor")) {
        polylineOptions.color(inlinePolylineOptions.getColor());
    }
    if (inlineStyle.isStyleSet("width")) {
        polylineOptions.width(inlinePolylineOptions.getWidth());
    }
    if (inlineStyle.isLineRandomColorMode()) {
        polylineOptions.color(KmlStyle.computeRandomColor(inlinePolylineOptions.getColor()));
    }
}
 
Example #30
Source File: FragMap.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(@NonNull Location location) {
    mLocation = location;
    if (!isAdded() || isDetached() || mMap == null)
        return;
    LatLng pos = new LatLng(location.getLatitude(), location.getLongitude());
    if (mLine != null) {
        ArrayList<LatLng> points = new ArrayList<>();
        points.add(pos);
        points.add(mKaabePos);
        mLine.setPoints(points);
        mMarker.setPosition(pos);
        mCircle.setCenter(pos);
        mCircle.setRadius(location.getAccuracy());
        mMap.animateCamera(CameraUpdateFactory.newLatLng(pos));
    } else {
        //zoom first time
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 15));


        mLine = mMap.addPolyline(
                new PolylineOptions().add(pos).add(mKaabePos).geodesic(true).color(Color.parseColor("#3bb2d0")).width(3).zIndex(1));

        mMarker = mMap.addMarker(
                new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_mylocation)).anchor(0.5f, 0.5f).position(pos)
                        .zIndex(2));

        mCircle = mMap.addCircle(
                new CircleOptions().center(pos).fillColor(0xAA4FC3F7).strokeColor(getResources().getColor(R.color.colorPrimary)).strokeWidth(2)
                        .radius(mLocation.getAccuracy()));
    }


}