Java Code Examples for com.google.android.gms.maps.model.CircleOptions

The following examples show how to use com.google.android.gms.maps.model.CircleOptions. These examples are extracted from open source projects. 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 Project: AndroidLocationStarterKit   Author: mizutori   File: MainActivity.java    License: MIT License 6 votes vote down vote up
private void drawLocationAccuracyCircle(Location location){
    if(location.getAccuracy() < 0){
        return;
    }

    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());

    if (this.locationAccuracyCircle == null) {
        this.locationAccuracyCircle = map.addCircle(new CircleOptions()
                .center(latLng)
                .fillColor(Color.argb(64, 0, 0, 0))
                .strokeColor(Color.argb(64, 0, 0, 0))
                .strokeWidth(0.0f)
                .radius(location.getAccuracy())); //set readius to horizonal accuracy in meter.
    } else {
        this.locationAccuracyCircle.setCenter(latLng);
    }
}
 
Example #2
Source Project: AndroidLocationStarterKit   Author: mizutori   File: MainActivity.java    License: MIT License 6 votes vote down vote up
private void drawPredictionRange(Location location){
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());

    if (this.predictionRange == null) {
        this.predictionRange = map.addCircle(new CircleOptions()
                .center(latLng)
                .fillColor(Color.argb(50, 30, 207, 0))
                .strokeColor(Color.argb(128, 30, 207, 0))
                .strokeWidth(1.0f)
                .radius(30)); //30 meters of the prediction range
    } else {
        this.predictionRange.setCenter(latLng);
    }

    this.predictionRange.setVisible(true);

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            MainActivity.this.predictionRange.setVisible(false);
        }
    }, 2000);
}
 
Example #3
Source Project: PowerSwitch_Android   Author: Power-Switch   File: MapViewHandler.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Add Geofence to Map
 *
 * @param latLng position
 * @param radius radius
 * @return Geofence
 */
public Geofence addGeofence(LatLng latLng, double radius) {
    MarkerOptions markerOptions = new MarkerOptions()
            .position(latLng)
            .draggable(true);
    Marker marker = googleMap.addMarker(markerOptions);

    CircleOptions circleOptions = new CircleOptions().center(latLng)
            .radius(radius)
            .fillColor(ContextCompat.getColor(context, R.color.geofenceFillColor))
            .strokeColor(Color.BLUE)
            .strokeWidth(2);
    Circle circle = googleMap.addCircle(circleOptions);

    circles.put(circle.getId(), circle);
    Geofence geofence = new Geofence(marker, circle);
    geofences.put(marker.getId(), geofence);

    return geofence;
}
 
Example #4
Source Project: android-samples   Author: googlemaps   File: CircleDemoActivity.java    License: Apache License 2.0 6 votes vote down vote up
public DraggableCircle(LatLng center, double radiusMeters) {
    this.radiusMeters = radiusMeters;
    centerMarker = map.addMarker(new MarkerOptions()
            .position(center)
            .draggable(true));
    radiusMarker = map.addMarker(new MarkerOptions()
            .position(toRadiusLatLng(center, radiusMeters))
            .draggable(true)
            .icon(BitmapDescriptorFactory.defaultMarker(
                    BitmapDescriptorFactory.HUE_AZURE)));
    circle = map.addCircle(new CircleOptions()
            .center(center)
            .radius(radiusMeters)
            .strokeWidth(strokeWidthBar.getProgress())
            .strokeColor(strokeColorArgb)
            .fillColor(fillColorArgb)
            .clickable(clickabilityCheckbox.isChecked()));
}
 
Example #5
Source Project: android-maps-utils   Author: googlemaps   File: HeatmapsPlacesDemoActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void startDemo(boolean isRestore) {
    EditText editText = findViewById(R.id.input_text);
    editText.setOnEditorActionListener((textView, actionId, keyEvent) -> {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_GO) {
            submit(null);
            handled = true;
        }
        return handled;
    });

    mCheckboxLayout = findViewById(R.id.checkboxes);
    GoogleMap map = getMap();
    if (!isRestore) {
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 11));
    }
    // Add a circle around Sydney to roughly encompass the results
    map.addCircle(new CircleOptions()
            .center(SYDNEY)
            .radius(SEARCH_RADIUS * 1.2)
            .strokeColor(Color.RED)
            .strokeWidth(4));
}
 
Example #6
Source Project: FimiX8-RE   Author: wladimir-computin   File: GglMapAiLineManager.java    License: MIT License 5 votes vote down vote up
public void drawAiLimit(double lat, double lng, double radiu) {
    if (this.limitCircle == null) {
        this.limitCircle = this.googleMap.addCircle(new CircleOptions().center(new LatLng(lat, lng)).radius(radiu).strokeColor(this.strokeColor).fillColor(this.fillColor).strokeWidth((float) this.strokeWidth));
        return;
    }
    this.limitCircle.setCenter(new LatLng(lat, lng));
}
 
Example #7
Source Project: FimiX8-RE   Author: wladimir-computin   File: GglMapAiSurroundManager.java    License: MIT License 5 votes vote down vote up
public void drawAiLimit(double lat, double lng, double radiu) {
    if (this.limitCircle == null) {
        this.limitCircle = this.googleMap.addCircle(new CircleOptions().center(new LatLng(lat, lng)).radius(radiu).strokeColor(this.strokeColor).fillColor(this.fillColor).strokeWidth((float) this.strokeWidth));
        return;
    }
    this.limitCircle.setCenter(new LatLng(lat, lng));
}
 
Example #8
Source Project: FimiX8-RE   Author: wladimir-computin   File: GglMapAiPoint2PointManager.java    License: MIT License 5 votes vote down vote up
public void drawAiLimit(double lat, double lng, double radiu) {
    if (this.limitCircle == null) {
        this.limitCircle = this.googleMap.addCircle(new CircleOptions().center(new LatLng(lat, lng)).radius(radiu).strokeColor(this.strokeColor).fillColor(this.fillColor).strokeWidth((float) this.strokeWidth));
        return;
    }
    this.limitCircle.setCenter(new LatLng(lat, lng));
}
 
Example #9
Source Project: Complete-Google-Map-API-Tutorial   Author: mohammadima3oud   File: ShapeActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void addCircle()
{
	googleMap.clear();
	CircleOptions circleOptions = new CircleOptions();
	circleOptions.center(new LatLng(37, 67));
	circleOptions.radius(100000);
	circleOptions.strokeColor(Color.RED);
	circleOptions.strokeWidth(10f);
	circleOptions.strokePattern(PATTERN_MIXED);
	circleOptions.clickable(true);
	circleOptions.fillColor(Color.GREEN);

	googleMap.addCircle(circleOptions).setTag(new CustomTag("circle"));
	googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(37, 67)));
}
 
Example #10
Source Project: LocationAware   Author: Arjun-sna   File: AlarmActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setMarkerOnMap(CheckPoint checkPoint) {
  if (googleMap != null) {
    LatLng latLng = new LatLng(checkPoint.getLatitude(), checkPoint.getLongitude());
    googleMap.addMarker(new MarkerOptions().position(
        latLng)
        .draggable(false)
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.flag)));
    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15), 10, null);
    googleMap.addCircle(new CircleOptions().center(latLng)
        .strokeWidth(5)
        .strokeColor(getResources().getColor(R.color.cardview_dark_background))
        .radius(500));
  }
}
 
Example #11
Source Project: JCVD   Author: djavan-bertrand   File: FenceRecyclerAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    googleMap.setMyLocationEnabled(true);
    googleMap.getUiSettings().setMyLocationButtonEnabled(false);

    StorableLocationFence locFence = null;
    if (!mFence.getAndFences().isEmpty()) {
        for (StorableFence andFence : mFence.getAndFences()) {
            if (andFence.getType().equals(StorableFence.Type.LOCATION)) {
                locFence = (StorableLocationFence) andFence;
            }
        }
    } else {
        if (mFence.getType().equals(StorableFence.Type.LOCATION)) {
            locFence = (StorableLocationFence) mFence;
        }
    }
    if (locFence != null) {
        LatLng latLng = new LatLng(locFence.getLatitude(), locFence.getLongitude());
        CircleOptions circleOptions = new CircleOptions()
                .center(latLng)
                .radius(locFence.getRadius()); // In meters

        googleMap.addCircle(circleOptions);

        CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(latLng)
                .zoom(14)
                .build();
        googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    }
}
 
Example #12
Source Project: prayer-times-android   Author: metinkale38   File: FragMap.java    License: 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()));
    }


}
 
Example #13
Source Project: LearningAppAndroid   Author: salesforce-marketingcloud   File: MapsActivity.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configures the google map
 * In case there is GeoLocations or Beacons
 *
 * @param map Google map to work on
 */
private void setUpMap(GoogleMap map) {
    MCLocationManager lm = MCLocationManager.getInstance();

    /* lastCoordinate is the location which the map will show, the default being San Francisco */
    LatLng lastCoordinate = new LatLng(Double.parseDouble(getResources().getString(R.string.default_latitude)),
            Double.parseDouble(getResources().getString(R.string.default_longitude)));

    /* Loops through the beacons and set them in the map */
    for (MCBeacon beacon : lm.getBeacons()) {
        map.addMarker(new MarkerOptions()
                .position(beacon.getCoordenates())
                .title(beacon.getName())
                .icon(BitmapDescriptorFactory.fromResource((R.drawable.tags))));
        map.addCircle(new CircleOptions()
                .center(beacon.getCoordenates())
                .radius(beacon.getRadius())
                .strokeColor(getResources().getColor(R.color.beaconOuterCircle))
                .fillColor(getResources().getColor(R.color.beaconInnerCircle)));
        lastCoordinate = beacon.getCoordenates();
    }

    /* Loops through the locations and set them in the map */
    for (MCGeofence location : lm.getGeofences()) {
        map.addMarker(new MarkerOptions().position(location.getCoordenates()).title(location.getName()));
        map.addCircle(new CircleOptions()
                .center(location.getCoordenates())
                .radius(location.getRadius())
                .strokeColor(getResources().getColor(R.color.geoLocationOuterCircle))
                .fillColor(getResources().getColor(R.color.geoLocationInnerCircle)));
        lastCoordinate = location.getCoordenates();
    }
    /* Centers the map in the last coordinate found and sets the zoom */
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(lastCoordinate).zoom(getResources().getInteger(R.integer.map_zoom)).build();
    map.animateCamera(CameraUpdateFactory
            .newCameraPosition(cameraPosition));
}
 
Example #14
Source Project: PowerSwitch_Android   Author: Power-Switch   File: MapViewHandler.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void updateGeofence(String id, CircleOptions circleOptions) {
    Geofence geofence = geofences.get(id);
    geofence.setRadius(circleOptions.getRadius());
    geofence.setCenter(circleOptions.getCenter());
    geofence.setVisible(circleOptions.isVisible());
    geofence.setFillColor(circleOptions.getFillColor());
    geofence.setStrokeColor(circleOptions.getStrokeColor());
    geofence.setStrokeWidth(circleOptions.getStrokeWidth());
    geofence.setZIndex(circleOptions.getZIndex());
}
 
Example #15
Source Project: mage-android   Author: ngageoint   File: ObservationMarkerCollection.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {

    boolean handled = false;

    Observation observation = mapObservations.getMarkerObservation(marker.getId());
    if (observation != null) {
        final Geometry g = observation.getGeometry();
        if (g != null) {
            Point point = GeometryUtils.getCentroid(g);
            LatLng latLng = new LatLng(point.getY(), point.getX());
            Float accuracy = observation.getAccuracy();
            if (accuracy != null) {
                try {
                    if (observationAccuracyCircle != null) {
                        observationAccuracyCircle.second.remove();
                    }

                    Circle circle = map.addCircle(new CircleOptions()
                        .center(latLng)
                        .radius(accuracy)
                        .fillColor(context.getResources().getColor(R.color.accuracy_circle_fill))
                        .strokeColor(context.getResources().getColor(R.color.accuracy_circle_stroke))
                        .strokeWidth(2.0f));

                    observationAccuracyCircle = new Pair<>(observation.getRemoteId(), circle);
                } catch (NumberFormatException nfe) {
                    Log.e(LOG_NAME, "Problem adding accuracy circle to the map.", nfe);
                }
            }
        }

        map.setInfoWindowAdapter(infoWindowAdapter);
        marker.showInfoWindow();
        handled = true;
    }

    return handled;
}
 
Example #16
Source Project: mage-android   Author: ngageoint   File: ObservationLocation.java    License: Apache License 2.0 5 votes vote down vote up
public CircleOptions getAccuracyCircle(Resources resources) {
    CircleOptions circle = null;
    if (geometry.getGeometryType() == GeometryType.POINT && !isManualProvider() && accuracy != null) {
        circle = new CircleOptions()
            .fillColor(resources.getColor(R.color.accuracy_circle_fill))
            .strokeColor(resources.getColor(R.color.accuracy_circle_stroke))
            .strokeWidth(2)
            .center(getFirstLatLng())
            .radius(accuracy);
    }

    return circle;
}
 
Example #17
Source Project: prayer-times-android   Author: metinkale38   File: FragMap.java    License: 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()));
    }


}
 
Example #18
Source Project: Android-GoogleMaps-Part1   Author: tutsplus   File: MapFragment.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void drawCircle( LatLng location ) {
    CircleOptions options = new CircleOptions();
    options.center( location );
    //Radius in meters
    options.radius( 10 );
    options.fillColor( getResources().getColor( R.color.fill_color ) );
    options.strokeColor( getResources().getColor( R.color.stroke_color ) );
    options.strokeWidth( 10 );
    getMap().addCircle(options);
}
 
Example #19
Source Project: AirMapView   Author: airbnb   File: NativeGoogleMapFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void drawCircle(LatLng latLng, int radius, int borderColor, int borderWidth,
    int fillColor) {
  googleMap.addCircle(new CircleOptions()
      .center(latLng)
      .strokeColor(borderColor)
      .strokeWidth(borderWidth)
      .fillColor(fillColor)
      .radius(radius));
}
 
Example #20
Source Project: AndroidDemoProjects   Author: PaulTR   File: MapFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void drawCircle( LatLng location ) {
    CircleOptions options = new CircleOptions();
    options.center( location );
    //Radius in meters
    options.radius( 10 );
    options.fillColor( getResources().getColor( R.color.fill_color ) );
    options.strokeColor( getResources().getColor( R.color.stroke_color ) );
    options.strokeWidth( 10 );
    getMap().addCircle(options);
}
 
Example #21
Source Project: homeassist   Author: axzae   File: MapActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setOnMarkerClickListener(this);
        UiSettings uiSettings = mMap.getUiSettings();
        uiSettings.setCompassEnabled(true);
        uiSettings.setZoomControlsEnabled(true);
        uiSettings.setMyLocationButtonEnabled(true);
        uiSettings.setAllGesturesEnabled(true);
        uiSettings.setMyLocationButtonEnabled(true);

        DatabaseManager databaseManager = DatabaseManager.getInstance(this);
        ArrayList<Entity> devices = databaseManager.getDeviceLocations();


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

        int zoneCount = 0;
        int deviceCount = 0;

        for (Entity device : devices) {
            Log.d("YouQi", "Device: " + CommonUtil.deflate(device));

            LatLng latLng = device.getLocation();
            if (latLng == null) continue;
            builder.include(latLng);

            if (device.isZone()) {
                zoneCount += 1;
                Log.d("YouQi", "Zone!!");
                Circle circle = mMap.addCircle(new CircleOptions()
                        .center(latLng)
//                        .strokeColor(Color.RED)
                        .strokeColor(Color.parseColor("#FF5722"))
                        .fillColor(Color.parseColor("#33FFAB91")));

                if (device.attributes.radius != null) {
                    circle.setRadius(device.attributes.radius.floatValue());
                }

                if (device.hasMdiIcon()) {
                    Log.d("YouQi", "hasMdiIcon");
                    mMap.addMarker(new MarkerOptions()
                            .icon(BitmapDescriptorFactory.fromBitmap(mifZoneIcon.makeMaterialIcon(device.getMdiIcon())))
                            .position(latLng)
                            .zIndex(1.0f)
                            .anchor(mifZoneIcon.getAnchorU(), mifZoneIcon.getAnchorV()));
                } else {
                    Log.d("YouQi", "nope");
                    mMap.addMarker(new MarkerOptions()
                            .icon(BitmapDescriptorFactory.fromBitmap(mifZoneText.makeIcon(device.getFriendlyName())))
                            .position(latLng)
                            .zIndex(1.0f)
                            .anchor(mifZoneText.getAnchorU(), mifZoneText.getAnchorV()));
                }

            } else if (device.isDeviceTracker()) {
                deviceCount += 1;
                Marker marker = createMarker(device);
                markers.put(device.entityId, marker);
            }
        }

        if (deviceCount == 0 && zoneCount == 0) {
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.3333395, -30.3274332), 2));

            new MaterialDialog.Builder(this)
                    .cancelable(false)
                    .title(R.string.title_nozone)
                    .content(R.string.content_nozone)
                    .positiveText(R.string.button_continue)
                    .positiveColorRes(R.color.md_red_500)
                    .buttonRippleColorRes(R.color.md_grey_200)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            dialog.dismiss();
                        }
                    })
                    .show();
        } else {
            LatLngBounds bounds = builder.build();
            int width = getResources().getDisplayMetrics().widthPixels;
            int height = getResources().getDisplayMetrics().heightPixels;
            int padding = (int) (width * 0.20); // offset from edges of the map 10% of screen
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);

            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(bounds.getCenter(), 10));
            mMap.animateCamera(cu);
        }
        //mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
 
Example #22
Source Project: android-rxgeofence   Author: esafirm   File: MapUtils.java    License: MIT License 4 votes vote down vote up
public static Circle addCircleFromPlace(GoogleMap googleMap, Place place) {
  return googleMap.addCircle(new CircleOptions().center(getLatLngFromPlace(place))
      .radius(place.getRad() * 1000)
      .fillColor(Color.argb(66, 255, 0, 255))
      .strokeColor(Color.argb(66, 0, 0, 0)));
}
 
Example #23
Source Project: mage-android   Author: ngageoint   File: LocationMarkerCollection.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
	Pair<Location, User> pair = markerIdToPair.get(marker.getId());
	if (pair == null) {
		return false;
	}

	Location location = pair.first;
	User user = pair.second;

	final Geometry g = location.getGeometry();
	if (g != null) {
		Point point = GeometryUtils.getCentroid(g);
		LatLng latLng = new LatLng(point.getY(), point.getX());
		LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
		if (accuracyProperty != null && !accuracyProperty.getValue().toString().trim().isEmpty()) {
			try {
				float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());
				if (clickedAccuracyCircle != null) {
					clickedAccuracyCircle.remove();
				}

				int color = LocationBitmapFactory.locationColor(context, location);
				clickedAccuracyCircle = map.addCircle(new CircleOptions()
						.center(latLng)
						.radius(accuracy)
						.fillColor(ColorUtils.setAlphaComponent(color, (int) (256 * .20)))
						.strokeColor(ColorUtils.setAlphaComponent(color, (int) (256 * .87)))
						.strokeWidth(2.0f));
				clickedAccuracyCircleUserId = user.getId();
			} catch (NumberFormatException nfe) {
				Log.e(LOG_NAME, "Problem adding accuracy circle to the map.", nfe);
			}
		}
	}

	map.setInfoWindowAdapter(infoWindowAdapter);
	// make sure to set the Anchor after this call as well, because the size of the icon might have changed
	marker.setIcon(LocationBitmapFactory.bitmapDescriptor(context, location, user));
	marker.setAnchor(0.5f, 1.0f);
	marker.showInfoWindow();
	return true;
}
 
Example #24
Source Project: mage-android   Author: ngageoint   File: ProfileActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
	map.setMapType(preferences.getInt(getString(R.string.baseLayerKey), getResources().getInteger(R.integer.baseLayerDefaultValue)));

	int dayNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
	if (dayNightMode == Configuration.UI_MODE_NIGHT_NO) {
		map.setMapStyle(null);
	} else {
		map.setMapStyle(MapStyleOptions.loadRawResourceStyle(getApplicationContext(), R.raw.map_theme_night));
	}


	if (latLng != null && icon != null) {
		map.addMarker(new MarkerOptions()
			.position(latLng)
			.icon(icon));

		LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
		if (accuracyProperty != null) {
			float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());

			int color = LocationBitmapFactory.locationColor(getApplicationContext(), location);
			map.addCircle(new CircleOptions()
				.center(latLng)
				.radius(accuracy)
				.fillColor(ColorUtils.setAlphaComponent(color, (int) (256 * .20)))
				.strokeColor(ColorUtils.setAlphaComponent(color, (int) (256 * .87)))
				.strokeWidth(2.0f));

			double latitudePadding = (accuracy / 111325);
			LatLngBounds bounds = new LatLngBounds(
					new LatLng(latLng.latitude - latitudePadding, latLng.longitude),
					new LatLng(latLng.latitude + latitudePadding, latLng.longitude));

			int minDimension = Math.min(mapView.getWidth(), mapView.getHeight());
			int padding = (int) Math.floor(minDimension / 5f);
			map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
		} else {
			map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17));
		}
	}
}
 
Example #25
Source Project: PhoneProfilesPlus   Author: henrichg   File: LocationGeofenceEditorActivity.java    License: Apache License 2.0 4 votes vote down vote up
private void updateEditedMarker(boolean setMapCamera) {
    if (mMap != null) {

        if (mLastLocation != null) {
            LatLng lastLocationGeofence = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
            if (lastLocationRadius == null) {
                lastLocationRadius = mMap.addCircle(new CircleOptions()
                        .center(lastLocationGeofence)
                        .radius(mLastLocation.getAccuracy())
                        .strokeColor(ContextCompat.getColor(this, R.color.map_last_location_marker_stroke))
                        .fillColor(ContextCompat.getColor(this, R.color.map_last_location_marker_fill))
                        .strokeWidth(5)
                        .zIndex(1));
            } else {
                lastLocationRadius.setRadius(mLastLocation.getAccuracy());
                lastLocationRadius.setCenter(lastLocationGeofence);
            }
        }

        if (mLocation != null) {
            LatLng editedGeofence = new LatLng(mLocation.getLatitude(), mLocation.getLongitude());
            if (editedMarker == null) {
                MarkerOptions markerOptions = new MarkerOptions();
                markerOptions.position(editedGeofence);
                editedMarker = mMap.addMarker(markerOptions);
            } else
                editedMarker.setPosition(editedGeofence);
            editedMarker.setTitle(geofenceNameEditText.getText().toString());

            if (editedRadius == null) {
                editedRadius = mMap.addCircle(new CircleOptions()
                        .center(editedGeofence)
                        .radius(geofence._radius)
                        .strokeColor(ContextCompat.getColor(this, R.color.map_edited_location_marker_stroke))
                        .fillColor(ContextCompat.getColor(this, R.color.map_edited_location_marker_fill))
                        .strokeWidth(5)
                        .zIndex(2));
            } else {
                editedRadius.setRadius(geofence._radius);
                editedRadius.setCenter(editedGeofence);
            }
            radiusValue.setText(String.valueOf(Math.round(geofence._radius)));

            if (setMapCamera) {
                if (editedRadius != null) {
                    try {
                        float zoom = getCircleZoomValue(mLocation.getLatitude(), mLocation.getLongitude(), geofence._radius,
                                                            mMap.getMinZoomLevel(), mMap.getMaxZoomLevel());
                        //PPApplication.logE("LocationGeofenceEditorActivity.updateEditedMarker", "zoom=" + zoom);
                        if (zoom > 16)
                            zoom = 16;
                        mMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));//, 1000, null);
                    } catch (StackOverflowError e) {
                        mMap.moveCamera(CameraUpdateFactory.newLatLng(editedGeofence));
                    }
                }
                else {
                    mMap.moveCamera(CameraUpdateFactory.newLatLng(editedGeofence));
                }
            }
        }
    }
    //else {
    //    Log.e("LocationGeofenceEditorActivity.updateEditedMarker", "mMap==null");
    //}
}
 
Example #26
Source Project: RxGoogleMaps   Author: minageorge5080   File: MapsActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapObservableProvider = new MapObservableProvider(mapFragment);

    disposable.add(mapObservableProvider.getMapReadyObservable()
            .subscribe(googleMap -> {
                CircleOptions circleOptions = new CircleOptions()
                        .center(new LatLng(0d, 0d))
                        .radius(100000)
                        .clickable(true);
                googleMap.addCircle(circleOptions);
                Log.d(TAG, "map ready");
            }, throwable -> Log.e(TAG, throwable.getLocalizedMessage())));


    disposable.add(mapObservableProvider.getMapLongClickObservable()
            .subscribe(latLng -> Log.d(TAG, "map long click"),
                    throwable -> Log.e(TAG, throwable.getLocalizedMessage())));

    disposable.add(mapObservableProvider.getMapClickObservable()
            .subscribe(latLng -> Log.d(TAG, "map click"),
                    throwable -> Log.e(TAG, throwable.getLocalizedMessage())));


    disposable.add(mapObservableProvider.getCameraMoveStartedObservable()
            .subscribe(integer -> Log.d(TAG, "map move started: " + integer),
                    throwable -> Log.e(TAG, throwable.getLocalizedMessage())));

    disposable.add(mapObservableProvider.getCameraMoveObservable()
            .subscribe(Void -> Log.d(TAG, "map move started"),
                    throwable -> Log.e(TAG, throwable.getLocalizedMessage())));

    disposable.add(mapObservableProvider.getCameraMoveCanceledObservable()
            .subscribe(Void -> Log.d(TAG, "map move canceled"),
                    throwable -> Log.e(TAG, throwable.getLocalizedMessage())));


    disposable.add(mapObservableProvider.getCameraIdleObservable()
            .subscribe(latLng -> Log.d(TAG, "map camera idle "),
                    throwable -> Log.e(TAG, throwable.getLocalizedMessage())));

    disposable.add(mapObservableProvider.getCircleClickObservable()
            .subscribe(circle -> Log.d(TAG, "circle clicked"),
                    throwable -> Log.e(TAG, throwable.getLocalizedMessage())));

}
 
Example #27
Source Project: android-samples   Author: googlemaps   File: TagsDemoActivity.java    License: Apache License 2.0 4 votes vote down vote up
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"));
}
 
Example #28
Source Project: android_packages_apps_GmsCore   Author: microg   File: CircleImpl.java    License: Apache License 2.0 4 votes vote down vote up
public CircleImpl(String id, CircleOptions options, MarkupListener listener) {
    this.id = id;
    this.listener = listener;
    this.options = options == null ? new CircleOptions() : options;
}
 
Example #29
Source Project: android_packages_apps_GmsCore   Author: microg   File: GoogleMapImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ICircleDelegate addCircle(CircleOptions options) throws RemoteException {
    return backendMap.add(new CircleImpl(getNextCircleId(), options, this));
}
 
Example #30
Source Project: android-maps-utils   Author: googlemaps   File: CircleManager.java    License: Apache License 2.0 4 votes vote down vote up
public Circle addCircle(CircleOptions opts) {
    Circle circle = mMap.addCircle(opts);
    super.add(circle);
    return circle;
}