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

The following examples show how to use com.google.android.gms.maps.model.CircleOptions. 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: CircleDemoActivity.java    From android-samples with 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 #2
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 #3
Source File: MainActivity.java    From AndroidLocationStarterKit with 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 #4
Source File: MainActivity.java    From AndroidLocationStarterKit with 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 #5
Source File: MapViewHandler.java    From PowerSwitch_Android with 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 #6
Source File: GglMapAiSurroundManager.java    From FimiX8-RE with 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 File: NativeGoogleMapFragment.java    From AirMapView with 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 #8
Source File: MapFragment.java    From AndroidDemoProjects with 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 #9
Source File: MapFragment.java    From Android-GoogleMaps-Part1 with 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 #10
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()));
    }


}
 
Example #11
Source File: ObservationLocation.java    From mage-android with 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 #12
Source File: ObservationMarkerCollection.java    From mage-android with 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 #13
Source File: MapViewHandler.java    From PowerSwitch_Android with 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 #14
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 #15
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()));
    }


}
 
Example #16
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 #17
Source File: AlarmActivity.java    From LocationAware with 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 #18
Source File: GglMapAiLineManager.java    From FimiX8-RE with 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 #19
Source File: ShapeActivity.java    From Complete-Google-Map-API-Tutorial with 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 #20
Source File: GglMapAiPoint2PointManager.java    From FimiX8-RE with 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 #21
Source File: CircleManager.java    From android-maps-utils with 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;
}
 
Example #22
Source File: CircleManager.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
public void addAll(java.util.Collection<CircleOptions> opts) {
    for (CircleOptions opt : opts) {
        addCircle(opt);
    }
}
 
Example #23
Source File: GoogleMapImpl.java    From android_packages_apps_GmsCore with 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 #24
Source File: CircleManager.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
public void addAll(java.util.Collection<CircleOptions> opts, boolean defaultVisible) {
    for (CircleOptions opt : opts) {
        addCircle(opt).setVisible(defaultVisible);
    }
}
 
Example #25
Source File: CircleImpl.java    From android_packages_apps_GmsCore with 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 #26
Source File: TagsDemoActivity.java    From android-samples with 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 #27
Source File: MapsActivity.java    From RxGoogleMaps with 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 #28
Source File: LocationGeofenceEditorActivity.java    From PhoneProfilesPlus with 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 #29
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));
		}
	}
}
 
Example #30
Source File: LocationMarkerCollection.java    From mage-android with 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;
}