Search in sources :

Example 11 with LatLng

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

the class MarkerCollisionDemoActivity method addMarkersToMap.

private void addMarkersToMap() {
    MarkerOptions defaultMarkerOptions = new MarkerOptions();
    // Add 100 markers to the map.
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            defaultMarkerOptions.position(new LatLng(SYDNEY.latitude + i, SYDNEY.longitude - j)).zIndex(i * 10 + j).title("zIndex:" + (i * 10 + j)).draggable(true);
            if ((i + j) % 3 == 0) {
                defaultMarkerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                defaultMarkerOptions.collisionBehavior(Marker.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY);
            } else if ((i + j) % 3 == 1) {
                defaultMarkerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
                defaultMarkerOptions.collisionBehavior(Marker.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL);
            } else {
                defaultMarkerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
                defaultMarkerOptions.collisionBehavior(Marker.CollisionBehavior.REQUIRED);
            }
            map.addMarker(defaultMarkerOptions);
        }
    }
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) LatLng(com.google.android.libraries.maps.model.LatLng)

Example 12 with LatLng

use of com.google.android.libraries.maps.model.LatLng 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 13 with LatLng

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

the class MarkerDemoActivity method addMarkersToMap.

private void addMarkersToMap() {
    // Uses a colored icon.
    mBrisbane = mMap.addMarker(new MarkerOptions().position(BRISBANE).title("Brisbane").snippet("Population: 2,074,200").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    // Uses a custom icon with the info window popping out of the center of the icon.
    mSydney = mMap.addMarker(new MarkerOptions().position(SYDNEY).title("Sydney").snippet("Population: 4,627,300").icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)).infoWindowAnchor(0.5f, 0.5f));
    // Creates a draggable marker. Long press to drag.
    mMelbourne = mMap.addMarker(new MarkerOptions().position(MELBOURNE).title("Melbourne").snippet("Population: 4,137,400").draggable(true));
    // Place four markers on top of each other with differing z-indexes.
    mDarwin1 = mMap.addMarker(new MarkerOptions().position(DARWIN).title("Darwin Marker 1").snippet("z-index 1").zIndex(1));
    mDarwin2 = mMap.addMarker(new MarkerOptions().position(DARWIN).title("Darwin Marker 2").snippet("z-index 2").zIndex(2));
    mDarwin3 = mMap.addMarker(new MarkerOptions().position(DARWIN).title("Darwin Marker 3").snippet("z-index 3").zIndex(3));
    mDarwin4 = mMap.addMarker(new MarkerOptions().position(DARWIN).title("Darwin Marker 4").snippet("z-index 4").zIndex(4));
    // A few more markers for good measure.
    mPerth = mMap.addMarker(new MarkerOptions().position(PERTH).title("Perth").snippet("Population: 1,738,800"));
    mAdelaide = mMap.addMarker(new MarkerOptions().position(ADELAIDE).title("Adelaide").snippet("Population: 1,213,000"));
    // Vector drawable resource as a marker icon.
    mMap.addMarker(new MarkerOptions().position(ALICE_SPRINGS).icon(vectorToBitmap(R.drawable.ic_android, Color.parseColor("#A4C639"))).title("Alice Springs"));
    // Creates a marker rainbow demonstrating how to create default marker icons of different
    // hues (colors).
    float rotation = mRotationBar.getProgress();
    boolean flat = mFlatBox.isChecked();
    int numMarkersInRainbow = 12;
    for (int i = 0; i < numMarkersInRainbow; i++) {
        Marker marker = mMap.addMarker(new MarkerOptions().position(new LatLng(-30 + 10 * Math.sin(i * Math.PI / (numMarkersInRainbow - 1)), 135 - 10 * Math.cos(i * Math.PI / (numMarkersInRainbow - 1)))).title("Marker " + i).icon(BitmapDescriptorFactory.defaultMarker(i * 360 / numMarkersInRainbow)).flat(flat).rotation(rotation));
        mMarkerRainbow.add(marker);
    }
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) Marker(com.google.android.libraries.maps.model.Marker) LatLng(com.google.android.libraries.maps.model.LatLng)

Example 14 with LatLng

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

the class CameraDemoActivity method addCameraTargetToPath.

// [START_EXCLUDE silent]
private void addCameraTargetToPath() {
    LatLng target = map.getCameraPosition().target;
    currPolylineOptions.add(target);
}
Also used : LatLng(com.google.android.libraries.maps.model.LatLng)

Example 15 with LatLng

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

the class CircleDemoActivity method onMapLongClick.

@Override
public void onMapLongClick(LatLng point) {
    // We know the center, let's place the outline at a point 3/4 along the view.
    View view = getSupportFragmentManager().findFragmentById(R.id.map).getView();
    LatLng radiusLatLng = map.getProjection().fromScreenLocation(new Point(view.getHeight() * 3 / 4, view.getWidth() * 3 / 4));
    // Create the circle.
    DraggableCircle circle = new DraggableCircle(point, toRadiusMeters(point, radiusLatLng));
    circles.add(circle);
}
Also used : LatLng(com.google.android.libraries.maps.model.LatLng) Point(android.graphics.Point) View(android.view.View) AdapterView(android.widget.AdapterView)

Aggregations

LatLng (com.google.android.libraries.maps.model.LatLng)31 JSONException (org.json.JSONException)8 MarkerOptions (com.google.android.libraries.maps.model.MarkerOptions)7 PluginMethod (com.getcapacitor.PluginMethod)5 PolylineOptions (com.google.android.libraries.maps.model.PolylineOptions)5 MyItem (com.google.maps.android.utils.demo.model.MyItem)5 InputStream (java.io.InputStream)5 JSONObject (org.json.JSONObject)5 PolygonOptions (com.google.android.libraries.maps.model.PolygonOptions)4 Nullable (androidx.annotation.Nullable)3 GoogleMap (com.google.android.libraries.maps.GoogleMap)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JSONArray (org.json.JSONArray)3 DisplayMetrics (android.util.DisplayMetrics)2 Log (android.util.Log)2 View (android.view.View)2 CircleOptions (com.google.android.libraries.maps.model.CircleOptions)2 LatLngBounds (com.google.android.libraries.maps.model.LatLngBounds)2 Marker (com.google.android.libraries.maps.model.Marker)2