Search in sources :

Example 1 with PolylineOptions

use of com.google.android.libraries.maps.model.PolylineOptions in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method addPolyline.

@PluginMethod()
public void addPolyline(final PluginCall call) {
    final JSArray points = call.getArray("points", new JSArray());
    getBridge().executeOnMainThread(new Runnable() {

        @Override
        public void run() {
            PolylineOptions polylineOptions = new PolylineOptions();
            for (int i = 0; i < points.length(); i++) {
                try {
                    JSONObject point = points.getJSONObject(i);
                    LatLng latLng = new LatLng(point.getDouble("latitude"), point.getDouble("longitude"));
                    polylineOptions.add(latLng);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            googleMap.addPolyline(polylineOptions);
            call.resolve();
        }
    });
}
Also used : JSONObject(org.json.JSONObject) JSArray(com.getcapacitor.JSArray) JSONException(org.json.JSONException) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions) PluginMethod(com.getcapacitor.PluginMethod)

Example 2 with PolylineOptions

use of com.google.android.libraries.maps.model.PolylineOptions in project android-maps-utils by googlemaps.

the class DistanceDemoActivity method startDemo.

@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();
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Example 3 with PolylineOptions

use of com.google.android.libraries.maps.model.PolylineOptions in project android-samples by googlemaps.

the class PolylineDemoActivity method onMapReady.

@Override
public void onMapReady(GoogleMap map) {
    // For accessibility mode. Ideally this string would be localised.
    map.setContentDescription("Google Map with polylines.");
    // Non-loop polyline that goes past Australian cities. Added before sydneyPolyline and would
    // normally be underneath, but increase Z-Index so that this line is on top.
    australiaPolyline = map.addPolyline(new PolylineOptions().add(PERTH, ADELAIDE, SYDNEY, MELBOURNE).pattern(Arrays.asList(new Dot(), new Gap(20.0f))).color(Color.MAGENTA).zIndex(1));
    // Geodesic polyline that goes around the world.
    worldPolyline = map.addPolyline(new PolylineOptions().add(LONDON, AUCKLAND, LOS_ANGELES, NEW_YORK, LONDON).width(5).color(Color.BLUE).geodesic(true).clickable(true));
    // Loop polyline centered at Sydney.
    int radius = 4;
    sydneyPolyline = map.addPolyline(new PolylineOptions().add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius)).add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude - radius)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude - radius)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude + radius)).add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius)).pattern(Arrays.asList(new Dash(45.0f), new Gap(10.0f))).color(Color.RED).width(5).clickable(true));
    // Create Melbourne polyline to show layering of polylines with same Z-Index. This is added
    // second so it will be layered on top of the Sydney polyline (both have Z-Index == 0).
    melbournePolyline = map.addPolyline(new PolylineOptions().add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude + radius)).add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude - radius)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude - radius)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude + radius)).add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude + radius)).color(Color.GREEN).width(5).clickable(true));
    map.moveCamera(CameraUpdateFactory.newLatLng(SYDNEY));
    selectedPolyline = australiaPolyline;
    polylineRadio.check(R.id.polyline_radio_australia);
    pager.addOnPageChangeListener(this);
    polylineRadio.setOnCheckedChangeListener(this);
    map.setOnPolylineClickListener(this);
}
Also used : Dash(com.google.android.libraries.maps.model.Dash) Gap(com.google.android.libraries.maps.model.Gap) Dot(com.google.android.libraries.maps.model.Dot) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Example 4 with PolylineOptions

use of com.google.android.libraries.maps.model.PolylineOptions in project android-samples by googlemaps.

the class LiteDemoActivity method addPolyObjects.

/**
 * Add a Polyline and a Polygon to the map.
 * The Polyline connects Melbourne, Adelaide and Perth. The Polygon is located in the Northern
 * Territory (Australia).
 */
private void addPolyObjects() {
    map.addPolyline((new PolylineOptions()).add(MELBOURNE, ADELAIDE, PERTH).color(Color.GREEN).width(5f));
    map.addPolygon(new PolygonOptions().add(POLYGON).fillColor(Color.CYAN).strokeColor(Color.BLUE).strokeWidth(5));
}
Also used : PolygonOptions(com.google.android.libraries.maps.model.PolygonOptions) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Example 5 with PolylineOptions

use of com.google.android.libraries.maps.model.PolylineOptions in project android-samples by googlemaps.

the class TagsDemoActivity method addObjectsToMap.

private void addObjectsToMap() {
    // A circle centered on Adelaide.
    mAdelaideCircle = mMap.addCircle(new CircleOptions().center(ADELAIDE).radius(500000).fillColor(Color.argb(150, 66, 173, 244)).strokeColor(Color.rgb(66, 173, 244)).clickable(true));
    mAdelaideCircle.setTag(new CustomTag("Adelaide circle"));
    // A ground overlay at Sydney.
    mSydneyGroundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.harbour_bridge)).position(SYDNEY, 700000).clickable(true));
    mSydneyGroundOverlay.setTag(new CustomTag("Sydney ground overlay"));
    // A marker at Hobart.
    mHobartMarker = mMap.addMarker(new MarkerOptions().position(HOBART));
    mHobartMarker.setTag(new CustomTag("Hobart marker"));
    // A polygon centered at Darwin.
    mDarwinPolygon = mMap.addPolygon(new PolygonOptions().add(new LatLng(DARWIN.latitude + 3, DARWIN.longitude - 3), new LatLng(DARWIN.latitude + 3, DARWIN.longitude + 3), new LatLng(DARWIN.latitude - 3, DARWIN.longitude + 3), new LatLng(DARWIN.latitude - 3, DARWIN.longitude - 3)).fillColor(Color.argb(150, 34, 173, 24)).strokeColor(Color.rgb(34, 173, 24)).clickable(true));
    mDarwinPolygon.setTag(new CustomTag("Darwin polygon"));
    // A polyline from Perth to Brisbane.
    mPolyline = mMap.addPolyline(new PolylineOptions().add(PERTH, BRISBANE).color(Color.rgb(103, 24, 173)).width(30).clickable(true));
    mPolyline.setTag(new CustomTag("Perth to Brisbane polyline"));
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) CircleOptions(com.google.android.libraries.maps.model.CircleOptions) GroundOverlayOptions(com.google.android.libraries.maps.model.GroundOverlayOptions) PolygonOptions(com.google.android.libraries.maps.model.PolygonOptions) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Aggregations

PolylineOptions (com.google.android.libraries.maps.model.PolylineOptions)6 LatLng (com.google.android.libraries.maps.model.LatLng)5 PolygonOptions (com.google.android.libraries.maps.model.PolygonOptions)3 MarkerOptions (com.google.android.libraries.maps.model.MarkerOptions)2 JSArray (com.getcapacitor.JSArray)1 PluginMethod (com.getcapacitor.PluginMethod)1 GoogleMap (com.google.android.libraries.maps.GoogleMap)1 CircleOptions (com.google.android.libraries.maps.model.CircleOptions)1 Dash (com.google.android.libraries.maps.model.Dash)1 Dot (com.google.android.libraries.maps.model.Dot)1 Gap (com.google.android.libraries.maps.model.Gap)1 GroundOverlayOptions (com.google.android.libraries.maps.model.GroundOverlayOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1