Java Code Examples for com.google.android.gms.maps.GoogleMap#addCircle()

The following examples show how to use com.google.android.gms.maps.GoogleMap#addCircle() . 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: HeatmapsPlacesDemoActivity.java    From android-maps-utils with 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 2
Source File: FenceRecyclerAdapter.java    From JCVD with 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 3
Source File: MapsActivity.java    From LearningAppAndroid with 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 4
Source File: MapUtils.java    From android-rxgeofence with 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 5
Source File: ProfileActivity.java    From mage-android with 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));
		}
	}
}