Java Code Examples for com.google.android.gms.maps.model.Marker#setIcon()

The following examples show how to use com.google.android.gms.maps.model.Marker#setIcon() . 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: GglMapAiLineManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void onMarkerDragEnd(Marker marker) {
    MapPointLatLng mp = (MapPointLatLng) marker.getTag();
    marker.setIcon(this.gdCustemMarkerView.createMapPioView(this.context, R.drawable.x8_img_ai_line_inreterst_max1, mp.altitude, mp.nPos, false, false));
    MapPointLatLng tmp = (MapPointLatLng) marker.getTag();
    tmp.isInrertestPointActive = true;
    tmp.latitude = marker.getPosition().latitude;
    tmp.longitude = marker.getPosition().longitude;
    int i = 0;
    for (MapPointLatLng mpl : this.mMapPointList) {
        if (mpl.mInrertestPoint != null && tmp == mpl.mInrertestPoint) {
            mpl.setAngle(getPointAngle(mpl, tmp));
            changePointMarker((Marker) this.mMarkerList.get(i), mpl, false);
        }
        i++;
    }
}
 
Example 2
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void changePointMarker(Marker marker, MapPointLatLng mpl, boolean isRelation) {
    int res;
    if (!mpl.isMapPoint) {
        changeAngleOrOnAngle(marker, mpl, isRelation);
    } else if (mpl.isIntertestPoint) {
        if (mpl.isSelect) {
            res = R.drawable.x8_img_ai_line_inreterst_max2;
        } else {
            res = R.drawable.x8_img_ai_line_inreterst_max1;
        }
        marker.setIcon(this.gdCustemMarkerView.createMapPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.isSelect, isRelation));
        marker.setAnchor(0.5f, 0.73802954f);
    } else if (mpl.mInrertestPoint != null) {
        if (mpl.isSelect) {
            res = R.drawable.x8_ai_line_point_with_angle2;
        } else {
            res = R.drawable.x8_ai_line_point_with_angle1;
        }
        marker.setIcon(this.gdCustemMarkerView.createMapPointWithPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.mInrertestPoint.nPos, mpl.showAngle, mpl.isSelect, isRelation));
        marker.setAnchor(0.5f, 0.5f);
    } else {
        changeAngleOrOnAngle(marker, mpl, isRelation);
    }
}
 
Example 3
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void changeAngleOrOnAngle(Marker marker, MapPointLatLng mpl, boolean isRelation) {
    BitmapDescriptor mBitmapDescriptor;
    int res;
    if (mpl.yawMode == 1 || mpl.yawMode == 2) {
        if (mpl.isSelect) {
            res = R.drawable.x8_ai_line_point_with_angle2;
        } else {
            res = R.drawable.x8_ai_line_point_with_angle1;
        }
        mBitmapDescriptor = this.gdCustemMarkerView.createMapPointAngleNoPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.showAngle, mpl.isSelect, isRelation);
    } else {
        if (mpl.isSelect) {
            res = R.drawable.x8_ai_line_point_no_angle2;
        } else {
            res = R.drawable.x8_ai_line_point_no_angle1;
        }
        mBitmapDescriptor = this.gdCustemMarkerView.createMapPointNoAngleNoPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.isSelect, isRelation);
    }
    marker.setIcon(mBitmapDescriptor);
    marker.setAnchor(0.5f, 0.64285713f);
}
 
Example 4
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void changeViewByRunning(Marker marker, MapPointLatLng mpl) {
    if (!mpl.isIntertestPoint) {
        int res;
        if (mpl.mInrertestPoint != null) {
            if (mpl.yawMode == 0) {
                res = R.drawable.x8_ai_line_point_with_angle2;
            } else {
                res = R.drawable.x8_ai_line_point_with_angle2;
            }
            marker.setIcon(this.gdCustemMarkerView.createPointEventWithPioView(this.context, getCurrentPointActionRes(mpl.action), res, mpl.altitude, mpl.nPos, mpl.showAngle, mpl.isSelect, false));
            marker.setAnchor(0.5f, 0.6846361f);
            return;
        }
        if (mpl.yawMode == 0) {
            res = R.drawable.x8_ai_line_point_no_angle2;
        } else {
            res = R.drawable.x8_ai_line_point_with_angle2;
        }
        marker.setIcon(this.gdCustemMarkerView.createPointEventNoPioView(this.context, getCurrentPointActionRes(mpl.action), res, mpl.altitude, mpl.nPos, mpl.showAngle, mpl.isSelect, false));
        marker.setAnchor(0.5f, 0.7962384f);
    }
}
 
Example 5
Source File: MovingMarkerActivity.java    From Airbnb-Android-Google-Map-View with MIT License 6 votes vote down vote up
/**
   * Highlight the marker by marker.
   */
  private void highLightMarker(Marker marker) {

/*
      for (Marker foundMarker : this.markers) {
	if (!foundMarker.equals(marker)) {
		foundMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
	} else {
		foundMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
		foundMarker.showInfoWindow();
	}
}
*/
      marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
      //  marker.showInfoWindow();
      //marker.remove();
      //Utils.bounceMarker(googleMap, marker);

      this.selectedMarker = marker;
  }
 
Example 6
Source File: MyHistoricalLocationMarkerCollection.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
public void refreshMarkerIcons(Filter<Temporal> filter) {
	for (Marker m : locationIdToMarker.values()) {
		Pair<Location, User> pair = markerIdToLocation.get(m.getId());
		Location location = pair.first;

		if (location != null) {
			boolean showWindow = m.isInfoWindowShown();
			// make sure to set the Anchor after this call as well, because the size of the icon might have changed
			m.setIcon(LocationBitmapFactory.dotBitmapDescriptor(context, location));
			m.setAnchor(0.5f, 1.0f);
			if (showWindow) {
				m.showInfoWindow();
			}
		}
	}
}
 
Example 7
Source File: ObservationMarkerCollection.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
 public void refreshMarkerIcons(Filter<Temporal> filter) {
     for (MapMarkerObservation mapMarkerObservation : mapObservations.getMarkers()) {
         Marker marker = mapMarkerObservation.getMarker();
         Observation observation = mapMarkerObservation.getObservation();
if (observation != null) {
             if (filter != null && !filter.passesFilter(observation)) {
                 this.remove(observation);
             } else {
                 boolean showWindow = marker.isInfoWindowShown();
                 // make sure to set the Anchor after this call as well, because the size of the icon might have changed
                 marker.setIcon(ObservationBitmapFactory.bitmapDescriptor(context, observation));
                 marker.setAnchor(0.5f, 1.0f);
                 if (showWindow) {
                     marker.showInfoWindow();
                 }
             }
         }
     }
 }
 
Example 8
Source File: MapViewHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
public void updateMarker(String id, MarkerOptions markerOptions) {
    Marker marker = markers.get(id);
    marker.setPosition(markerOptions.getPosition());
    marker.setAlpha(markerOptions.getAlpha());
    marker.setDraggable(markerOptions.isDraggable());
    marker.setFlat(markerOptions.isFlat());
    marker.setIcon(markerOptions.getIcon());
    marker.setVisible(markerOptions.isVisible());
    marker.setTitle(markerOptions.getTitle());
    marker.setSnippet(markerOptions.getSnippet());
    marker.setRotation(markerOptions.getRotation());
    marker.setAnchor(markerOptions.getAnchorU(), markerOptions.getAnchorV());
    marker.setInfoWindowAnchor(markerOptions.getInfoWindowAnchorU(), markerOptions.getInfoWindowAnchorV());
}
 
Example 9
Source File: KmlRenderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Enlarges or shrinks a bitmap image based on the scale provided
 *
 * @param style  Style to retrieve iconUrl and scale from
 * @param marker Marker to set the image to
 */
private void scaleBitmap(KmlStyle style, Marker marker) {
    double bitmapScale = style.getIconScale();
    String bitmapUrl = style.getIconUrl();
    BitmapDescriptor scaledBitmap = getCachedMarkerImage(bitmapUrl, bitmapScale);
    marker.setIcon(scaledBitmap);
}
 
Example 10
Source File: SaveStateDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
    float newHue = MARKER_HUES[new Random().nextInt(MARKER_HUES.length)];
    mMarkerInfo.mHue = newHue;
    marker.setIcon(BitmapDescriptorFactory.defaultMarker(newHue));
    return true;
}
 
Example 11
Source File: LocationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void refreshMarkerIcons(Filter<Temporal> filter) {
	Collection<Marker> markers = new ArrayList<>(userIdToMarker.values());
	for (Marker m : markers) {
		Pair<Location, User> pair = markerIdToPair.get(m.getId());
		Location location = pair.first;
		User user = pair.second;
		if (location != null) {
			if (filter != null && !filter.passesFilter(location)) {
				remove(pair);
			} else {
				boolean showWindow = m.isInfoWindowShown();
				try {
					// make sure to set the Anchor after this call as well, because the size of the icon might have changed
					m.setIcon(LocationBitmapFactory.bitmapDescriptor(context, location, user));
					m.setAnchor(0.5f, 1.0f);
				} catch (Exception ue) {
					Log.e(LOG_NAME, "Error refreshing the icon for user: " + user.getId(), ue);
				}

				if (showWindow) {
					m.showInfoWindow();
				}
			}
		}
	}
}
 
Example 12
Source File: LocationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void refresh(Pair<Location, User> pair) {
	// TODO Maybe a different generic for this case
	// TODO implementing room might help solve this problem
	// In this case I know just the user is coming in
	// grab the location based on that
	User user = pair.second;
	Marker marker = userIdToMarker.get(pair.second.getId());

	if (marker != null) {
		Location location = markerIdToPair.get(marker.getId()).first;
		markerIdToPair.put(marker.getId(), new Pair(location, user));
		marker.setIcon(LocationBitmapFactory.bitmapDescriptor(context, location, user));
	}
}
 
Example 13
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void changeLineSmallMarkerByRunning(Marker marker1, Marker marker2, float angle, int type) {
    int res = 0;
    if (type == 0) {
        res = R.drawable.x8_ai_line_point_small1;
    } else if (type == 1) {
        res = R.drawable.x8_ai_line_point_small3;
    } else if (type == 2) {
        res = R.drawable.x8_ai_line_point_small2;
    }
    marker1.setIcon(this.gdCustemMarkerView.createPointWithSmallArrow(this.context, res, angle, ((MapPointLatLng) marker2.getTag()).isSelect));
    marker1.setAnchor(0.5f, 0.5f);
    marker2.setIcon(this.gdCustemMarkerView.createPointWithSmallArrow(this.context, res, angle, ((MapPointLatLng) marker2.getTag()).isSelect));
    marker2.setAnchor(0.5f, 0.5f);
}
 
Example 14
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;
}
 
Example 15
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public void onMarkerDragStart(Marker marker) {
    MapPointLatLng mp = (MapPointLatLng) marker.getTag();
    marker.setIcon(this.gdCustemMarkerView.createMapPioView(this.context, R.drawable.x8_img_ai_line_inreterst_max2, mp.altitude, mp.nPos, true, false));
}
 
Example 16
Source File: MovingMarkerActivity.java    From Airbnb-Android-Google-Map-View with MIT License 4 votes vote down vote up
private void resetMarkers() {
    for (Marker marker : this.markers) {
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
    }
}
 
Example 17
Source File: MarkerDemoActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(
                        1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }

    // Markers have a z-index that is settable and gettable.
    float zIndex = marker.getZIndex() + 1.0f;
    marker.setZIndex(zIndex);
    Toast.makeText(this, marker.getTitle() + " z-index set to " + zIndex,
            Toast.LENGTH_SHORT).show();

    mLastSelectedMarker = marker;
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}
 
Example 18
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public void changeViewBySetPoints(Marker marker, MapPointLatLng mpl, boolean isRelation, boolean isRun) {
    int res;
    if (mpl.isMapPoint) {
        float anchorY;
        BitmapDescriptor mBitmapDescriptor;
        if (mpl.isIntertestPoint) {
            changePointMarker(marker, mpl, false);
        } else if (mpl.yawMode == 0) {
            if (mpl.mInrertestPoint != null) {
                anchorY = 0.5f;
                if (mpl.isSelect) {
                    res = R.drawable.x8_ai_line_point_with_angle2;
                } else if (isRun) {
                    res = R.drawable.x8_ai_line_point_run_angle1;
                } else {
                    res = R.drawable.x8_ai_line_point_with_angle1;
                }
                mBitmapDescriptor = this.gdCustemMarkerView.createMapPointWithPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.mInrertestPoint.nPos, mpl.showAngle, mpl.isSelect, isRelation);
            } else {
                anchorY = 0.64285713f;
                if (mpl.isSelect) {
                    res = R.drawable.x8_ai_line_point_no_angle2;
                } else if (isRun) {
                    res = R.drawable.x8_ai_line_point_run_no_angle1;
                } else {
                    res = R.drawable.x8_ai_line_point_no_angle1;
                }
                mBitmapDescriptor = this.gdCustemMarkerView.createMapPointNoAngleNoPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.isSelect, isRelation);
                marker.setIcon(mBitmapDescriptor);
                marker.setAnchor(0.5f, 0.64285713f);
            }
            marker.setIcon(mBitmapDescriptor);
            marker.setAnchor(0.5f, anchorY);
        } else {
            if (mpl.mInrertestPoint != null) {
                anchorY = 0.5f;
                if (mpl.isSelect) {
                    res = R.drawable.x8_ai_line_point_with_angle2;
                } else if (isRun) {
                    res = R.drawable.x8_ai_line_point_run_angle1;
                } else {
                    res = R.drawable.x8_ai_line_point_with_angle1;
                }
                mBitmapDescriptor = this.gdCustemMarkerView.createMapPointWithPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.mInrertestPoint.nPos, mpl.showAngle, mpl.isSelect, isRelation);
            } else {
                anchorY = 0.64285713f;
                if (mpl.isSelect) {
                    res = R.drawable.x8_ai_line_point_with_angle2;
                } else if (isRun) {
                    res = R.drawable.x8_ai_line_point_run_angle1;
                } else {
                    res = R.drawable.x8_ai_line_point_with_angle1;
                }
                mBitmapDescriptor = this.gdCustemMarkerView.createMapPointAngleNoPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.showAngle, mpl.isSelect, isRelation);
            }
            marker.setIcon(mBitmapDescriptor);
            marker.setAnchor(0.5f, anchorY);
        }
    } else if (mpl.yawMode == 0) {
        if (mpl.isSelect) {
            res = R.drawable.x8_ai_line_point_no_angle2;
        } else if (isRun) {
            res = R.drawable.x8_ai_line_point_run_no_angle1;
        } else {
            res = R.drawable.x8_ai_line_point_no_angle1;
        }
        marker.setIcon(this.gdCustemMarkerView.createMapPointNoAngleNoPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.isSelect, isRelation));
        marker.setAnchor(0.5f, 0.64285713f);
    } else {
        if (mpl.isSelect) {
            res = R.drawable.x8_ai_line_point_with_angle2;
        } else if (isRun) {
            res = R.drawable.x8_ai_line_point_run_angle1;
        } else {
            res = R.drawable.x8_ai_line_point_with_angle1;
        }
        marker.setIcon(this.gdCustemMarkerView.createMapPointAngleNoPioView(this.context, res, mpl.altitude, mpl.nPos, mpl.showAngle, mpl.isSelect, isRelation));
        marker.setAnchor(0.5f, 0.64285713f);
    }
}
 
Example 19
Source File: CustomMarkerClusteringDemoActivity.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
@Override
protected void onClusterUpdated(@NonNull Cluster<Person> cluster, Marker marker) {
    // Same implementation as onBeforeClusterRendered() (to update cached markers)
    marker.setIcon(getClusterIcon(cluster));
}
 
Example 20
Source File: DefaultClusterRenderer.java    From android-maps-utils with Apache License 2.0 2 votes vote down vote up
/**
 * Called when a cached marker for a Cluster already exists on the map so the marker may
 * be updated to the latest cluster values. Default implementation updated the icon with a
 * circle with a rough count of the number of items. Note that the contents of the cluster may
 * not have changed since the cached marker was created - implementations of this method are
 * responsible for checking if something changed (if that matters to the implementation).
 *
 * The first time {@link ClusterManager#cluster()} is invoked on a set of items
 * {@link #onBeforeClusterRendered(Cluster, MarkerOptions)} will be called and
 * {@link #onClusterUpdated(Cluster, Marker)} will not be called. If an item is removed and
 * re-added (or updated) and {@link ClusterManager#cluster()} is invoked
 * again, then {@link #onClusterUpdated(Cluster, Marker)} will be called and
 * {@link #onBeforeClusterRendered(Cluster, MarkerOptions)} will not be called.
 *
 * @param cluster cluster being updated
 * @param marker cached marker that contains a potentially previous state of the cluster
 */
protected void onClusterUpdated(@NonNull Cluster<T> cluster, @NonNull Marker marker) {
    // TODO: consider adding anchor(.5, .5) (Individual markers will overlap more often)
    marker.setIcon(getDescriptorForCluster(cluster));
}