Java Code Examples for com.google.android.gms.maps.model.MarkerOptions#anchor()

The following examples show how to use com.google.android.gms.maps.model.MarkerOptions#anchor() . 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: StyleUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Set the icon into the marker options
 *
 * @param markerOptions marker options
 * @param icon          icon row
 * @param density       display density: {@link android.util.DisplayMetrics#density}
 * @param iconCache     icon cache
 * @return true if icon was set into the marker options
 */
public static boolean setIcon(MarkerOptions markerOptions, IconRow icon, float density, IconCache iconCache) {

    boolean iconSet = false;

    if (icon != null) {

        Bitmap iconImage = createIcon(icon, density, iconCache);
        markerOptions.icon(BitmapDescriptorFactory
                .fromBitmap(iconImage));
        iconSet = true;

        double anchorU = icon.getAnchorUOrDefault();
        double anchorV = icon.getAnchorVOrDefault();

        markerOptions.anchor((float) anchorU, (float) anchorV);
    }

    return iconSet;
}
 
Example 2
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Add a list of LatLngs to the map
 *
 * @param map     google map
 * @param latLngs lat lngs
 * @return multi marker
 */
public static MultiMarker addLatLngsToMap(GoogleMap map, MultiLatLng latLngs) {
    MultiMarker multiMarker = new MultiMarker();
    for (LatLng latLng : latLngs.getLatLngs()) {
        MarkerOptions markerOptions = new MarkerOptions();
        if (latLngs.getMarkerOptions() != null) {
            markerOptions.icon(latLngs.getMarkerOptions().getIcon());
            markerOptions.anchor(latLngs.getMarkerOptions().getAnchorU(),
                    markerOptions.getAnchorV());
            markerOptions.draggable(latLngs.getMarkerOptions()
                    .isDraggable());
            markerOptions.visible(latLngs.getMarkerOptions().isVisible());
            markerOptions.zIndex(latLngs.getMarkerOptions().getZIndex());
        }
        Marker marker = addLatLngToMap(map, latLng, markerOptions);
        multiMarker.add(marker);
    }
    return multiMarker;
}
 
Example 3
Source File: GeoJsonPointStyle.java    From android-maps-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a new MarkerOptions object containing styles for the GeoJsonPoint
 *
 * @return new MarkerOptions object
 */
public MarkerOptions toMarkerOptions() {
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.alpha(mMarkerOptions.getAlpha());
    markerOptions.anchor(mMarkerOptions.getAnchorU(), mMarkerOptions.getAnchorV());
    markerOptions.draggable(mMarkerOptions.isDraggable());
    markerOptions.flat(mMarkerOptions.isFlat());
    markerOptions.icon(mMarkerOptions.getIcon());
    markerOptions.infoWindowAnchor(mMarkerOptions.getInfoWindowAnchorU(),
            mMarkerOptions.getInfoWindowAnchorV());
    markerOptions.rotation(mMarkerOptions.getRotation());
    markerOptions.snippet(mMarkerOptions.getSnippet());
    markerOptions.title(mMarkerOptions.getTitle());
    markerOptions.visible(mMarkerOptions.isVisible());
    markerOptions.zIndex(mMarkerOptions.getZIndex());
    return markerOptions;
}
 
Example 4
Source File: MapWrapper.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void addMarker(final Marker aMarker) {
	final MarkerOptions marker = new MarkerOptions();
	marker.position(new LatLng(aMarker.latitude, aMarker.longitude));
	if (!TextUtils.isEmpty(aMarker.title)) {
		marker.title(aMarker.title);
	}
	if (!TextUtils.isEmpty(aMarker.snippet)) {
		marker.snippet(aMarker.snippet);
	}
	if (aMarker.bitmap != null) {
		marker.icon(BitmapDescriptorFactory.fromBitmap(aMarker.bitmap));
	} else {
		if (aMarker.icon != 0) {
			marker.icon(BitmapDescriptorFactory.fromResource(aMarker.icon));
		}
	}
	if (aMarker.anchor == Marker.Anchor.CENTER) {
		marker.anchor(0.5f, 0.5f);
	}
	mGoogleMap.addMarker(marker);
}
 
Example 5
Source File: ToastedMarkerOptionsChooser.java    From clusterkraf with Apache License 2.0 5 votes vote down vote up
@Override
public void choose(MarkerOptions markerOptions, ClusterPoint clusterPoint) {
	Context context = contextRef.get();
	if (context != null) {
		Resources res = context.getResources();
		boolean isCluster = clusterPoint.size() > 1;
		boolean hasTwoToasters = clusterPoint.containsInputPoint(twoToasters);
		BitmapDescriptor icon;
		String title;
		if (isCluster) {
			title = res.getQuantityString(R.plurals.count_points, clusterPoint.size(), clusterPoint.size());
			int clusterSize = clusterPoint.size();
			if (hasTwoToasters) {
				icon = BitmapDescriptorFactory.fromBitmap(getClusterBitmap(res, R.drawable.ic_map_pin_cluster_toaster, clusterSize));
				title = res.getString(R.string.including_two_toasters, title);
			} else {
				icon = BitmapDescriptorFactory.fromBitmap(getClusterBitmap(res, R.drawable.ic_map_pin_cluster, clusterSize));
				title = res.getQuantityString(R.plurals.count_points, clusterSize, clusterSize);
			}
		} else {
			MarkerData data = (MarkerData)clusterPoint.getPointAtOffset(0).getTag();
			if (hasTwoToasters) {
				icon = BitmapDescriptorFactory.fromResource(R.drawable.ic_map_pin_toaster);
				title = data.getLabel();
			} else {
				icon = BitmapDescriptorFactory.fromResource(R.drawable.ic_map_pin);
				title = res.getString(R.string.point_number_x, data.getLabel());
			}
		}
		markerOptions.icon(icon);
		markerOptions.title(title);
		markerOptions.anchor(0.5f, 1.0f);
	}
}
 
Example 6
Source File: ChatAttachAlertLocationLayout.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void updatePlacesMarkers(ArrayList<TLRPC.TL_messageMediaVenue> places) {
    if (places == null) {
        return;
    }
    for (int a = 0, N = placeMarkers.size(); a < N; a++) {
        placeMarkers.get(a).marker.remove();
    }
    placeMarkers.clear();
    for (int a = 0, N = places.size(); a < N; a++) {
        TLRPC.TL_messageMediaVenue venue = places.get(a);
        try {
            MarkerOptions options = new MarkerOptions().position(new LatLng(venue.geo.lat, venue.geo._long));
            options.icon(BitmapDescriptorFactory.fromBitmap(createPlaceBitmap(a)));
            options.anchor(0.5f, 0.5f);
            options.title(venue.title);
            options.snippet(venue.address);
            VenueLocation venueLocation = new VenueLocation();
            venueLocation.num = a;
            venueLocation.marker = googleMap.addMarker(options);
            venueLocation.venue = venue;
            venueLocation.marker.setTag(venueLocation);
            placeMarkers.add(venueLocation);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
 
Example 7
Source File: LocationActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private LiveLocation addUserMarker(TLRPC.TL_channelLocation location) {
    LatLng latLng = new LatLng(location.geo_point.lat, location.geo_point._long);
    LiveLocation liveLocation = new LiveLocation();
    int did = (int) dialogId;
    if (did > 0) {
        liveLocation.user = getMessagesController().getUser(did);
        liveLocation.id = did;
    } else {
        liveLocation.chat = getMessagesController().getChat(-did);
        liveLocation.id = did;
    }

    try {
        MarkerOptions options = new MarkerOptions().position(latLng);
        Bitmap bitmap = createUserBitmap(liveLocation);
        if (bitmap != null) {
            options.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
            options.anchor(0.5f, 0.907f);
            liveLocation.marker = googleMap.addMarker(options);
            markers.add(liveLocation);
            markersMap.put(liveLocation.id, liveLocation);
        }
    } catch (Exception e) {
        FileLog.e(e);
    }

    return liveLocation;
}
 
Example 8
Source File: LocationActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void updatePlacesMarkers(ArrayList<TLRPC.TL_messageMediaVenue> places) {
    if (places == null) {
        return;
    }
    for (int a = 0, N = placeMarkers.size(); a < N; a++) {
        placeMarkers.get(a).marker.remove();
    }
    placeMarkers.clear();
    for (int a = 0, N = places.size(); a < N; a++) {
        TLRPC.TL_messageMediaVenue venue = places.get(a);
        try {
            MarkerOptions options = new MarkerOptions().position(new LatLng(venue.geo.lat, venue.geo._long));
            options.icon(BitmapDescriptorFactory.fromBitmap(createPlaceBitmap(a)));
            options.anchor(0.5f, 0.5f);
            options.title(venue.title);
            options.snippet(venue.address);
            VenueLocation venueLocation = new VenueLocation();
            venueLocation.num = a;
            venueLocation.marker = googleMap.addMarker(options);
            venueLocation.venue = venue;
            venueLocation.marker.setTag(venueLocation);
            placeMarkers.add(venueLocation);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
 
Example 9
Source File: KmlStyle.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new marker option from given properties of an existing marker option
 *
 * @param originalMarkerOption An existing MarkerOption instance
 * @param iconRandomColorMode  True if marker color mode is random, false otherwise
 * @param markerColor          Color of the marker
 * @return A new MarkerOption
 */
private static MarkerOptions createMarkerOptions(MarkerOptions originalMarkerOption,
                                                 boolean iconRandomColorMode, float markerColor) {
    MarkerOptions newMarkerOption = new MarkerOptions();
    newMarkerOption.rotation(originalMarkerOption.getRotation());
    newMarkerOption.anchor(originalMarkerOption.getAnchorU(), originalMarkerOption.getAnchorV());
    if (iconRandomColorMode) {
        float hue = getHueValue(computeRandomColor((int) markerColor));
        originalMarkerOption.icon(BitmapDescriptorFactory.defaultMarker(hue));
    }
    newMarkerOption.icon(originalMarkerOption.getIcon());
    return newMarkerOption;
}
 
Example 10
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the inline point style by copying over the styles that have been set
 *
 * @param markerOptions marker options object to add inline styles to
 * @param inlineStyle   inline styles to apply
 * @param defaultStyle  default shared style
 */
private void setInlinePointStyle(MarkerOptions markerOptions, KmlStyle inlineStyle,
                                 KmlStyle defaultStyle) {
    MarkerOptions inlineMarkerOptions = inlineStyle.getMarkerOptions();
    if (inlineStyle.isStyleSet("heading")) {
        markerOptions.rotation(inlineMarkerOptions.getRotation());
    }
    if (inlineStyle.isStyleSet("hotSpot")) {
        markerOptions
                .anchor(inlineMarkerOptions.getAnchorU(), inlineMarkerOptions.getAnchorV());
    }
    if (inlineStyle.isStyleSet("markerColor")) {
        markerOptions.icon(inlineMarkerOptions.getIcon());
    }
    double scale;
    if (inlineStyle.isStyleSet("iconScale")) {
        scale = inlineStyle.getIconScale();
    } else if (defaultStyle.isStyleSet("iconScale")) {
        scale = defaultStyle.getIconScale();
    } else {
        scale = 1.0;
    }
    if (inlineStyle.isStyleSet("iconUrl")) {
        addMarkerIcons(inlineStyle.getIconUrl(), scale, markerOptions);
    } else if (defaultStyle.getIconUrl() != null) {
        // Inline style with no icon defined
        addMarkerIcons(defaultStyle.getIconUrl(), scale, markerOptions);
    }
}
 
Example 11
Source File: MapMarker.java    From android-app with GNU General Public License v2.0 5 votes vote down vote up
private MarkerOptions getMarker(Spot spot, float hueColor, Itinerary itinerary) {
    MarkerOptions options = new MarkerOptions();
    LatLng position = new LatLng(spot.getLatitude(), spot.getLongitude());
    options.position(position);
    options.anchor(0.0f, 1.0f);
    options.icon(BitmapDescriptorFactory.defaultMarker(hueColor));
    options.snippet(new Gson().toJson(itinerary)+">"+spot.getReturning());
    return options;
}
 
Example 12
Source File: MapMarker.java    From android-app with GNU General Public License v2.0 5 votes vote down vote up
private MarkerOptions getMarker(Bus bus) {
    MarkerOptions options = new MarkerOptions();
    LatLng position = new LatLng(bus.getLatitude(), bus.getLongitude());
    options.position(position);
    options.anchor(0.0f, 1.0f);
    options.icon(getIcon(bus.getTimestamp()));
    options.snippet(new Gson().toJson(bus));
    return options;
}
 
Example 13
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Add a shape marker to the map at the location.  A shape marker is a transparent icon for allowing shape info windows.
 *
 * @param latLng  lat lng location
 * @param visible visible state
 * @return shape marker
 */
public Marker addShapeMarker(LatLng latLng, boolean visible) {

    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)));
    markerOptions.visible(visible);
    markerOptions.anchor(0.5f, 0.5f);
    markerOptions.position(latLng);
    Marker marker = map.addMarker(markerOptions);

    return marker;
}
 
Example 14
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Add the list of points as markers
 *
 * @param map                 google map
 * @param points              points
 * @param customMarkerOptions custom marker options
 * @param ignoreIdenticalEnds ignore identical ends flag
 * @return list of markers
 */
public List<Marker> addPointsToMapAsMarkers(GoogleMap map,
                                            List<LatLng> points, MarkerOptions customMarkerOptions,
                                            boolean ignoreIdenticalEnds) {

    List<Marker> markers = new ArrayList<Marker>();
    for (int i = 0; i < points.size(); i++) {
        LatLng latLng = points.get(i);

        if (points.size() > 1 && i + 1 == points.size() && ignoreIdenticalEnds) {
            LatLng firstLatLng = points.get(0);
            if (latLng.latitude == firstLatLng.latitude
                    && latLng.longitude == firstLatLng.longitude) {
                break;
            }
        }

        MarkerOptions markerOptions = new MarkerOptions();
        if (customMarkerOptions != null) {
            markerOptions.icon(customMarkerOptions.getIcon());
            markerOptions.anchor(customMarkerOptions.getAnchorU(),
                    customMarkerOptions.getAnchorV());
            markerOptions.draggable(customMarkerOptions.isDraggable());
            markerOptions.visible(customMarkerOptions.isVisible());
            markerOptions.zIndex(customMarkerOptions.getZIndex());
        }
        Marker marker = addLatLngToMap(map, latLng, markerOptions);
        markers.add(marker);
    }
    return markers;
}
 
Example 15
Source File: LocationActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private LiveLocation addUserMarker(TLRPC.Message message) {
    LiveLocation liveLocation;
    LatLng latLng = new LatLng(message.media.geo.lat, message.media.geo._long);
    if ((liveLocation = markersMap.get(message.from_id)) == null) {
        liveLocation = new LiveLocation();
        liveLocation.object = message;
        if (liveLocation.object.from_id != 0) {
            liveLocation.user = getMessagesController().getUser(liveLocation.object.from_id);
            liveLocation.id = liveLocation.object.from_id;
        } else {
            int did = (int) MessageObject.getDialogId(message);
            if (did > 0) {
                liveLocation.user = getMessagesController().getUser(did);
                liveLocation.id = did;
            } else {
                liveLocation.chat = getMessagesController().getChat(-did);
                liveLocation.id = did;
            }
        }

        try {
            MarkerOptions options = new MarkerOptions().position(latLng);
            Bitmap bitmap = createUserBitmap(liveLocation);
            if (bitmap != null) {
                options.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
                options.anchor(0.5f, 0.907f);
                liveLocation.marker = googleMap.addMarker(options);
                markers.add(liveLocation);
                markersMap.put(liveLocation.id, liveLocation);
                LocationController.SharingLocationInfo myInfo = getLocationController().getSharingLocationInfo(dialogId);
                if (liveLocation.id == getUserConfig().getClientUserId() && myInfo != null && liveLocation.object.id == myInfo.mid && myLocation != null) {
                    liveLocation.marker.setPosition(new LatLng(myLocation.getLatitude(), myLocation.getLongitude()));
                }
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        liveLocation.object = message;
        liveLocation.marker.setPosition(latLng);
    }
    return liveLocation;
}
 
Example 16
Source File: LocationActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private LiveLocation addUserMarker(TLRPC.Message message) {
    LiveLocation liveLocation;
    LatLng latLng = new LatLng(message.media.geo.lat, message.media.geo._long);
    if ((liveLocation = markersMap.get(message.from_id)) == null) {
        liveLocation = new LiveLocation();
        liveLocation.object = message;
        if (liveLocation.object.from_id != 0) {
            liveLocation.user = MessagesController.getInstance(currentAccount).getUser(liveLocation.object.from_id);
            liveLocation.id = liveLocation.object.from_id;
        } else {
            int did = (int) MessageObject.getDialogId(message);
            if (did > 0) {
                liveLocation.user = MessagesController.getInstance(currentAccount).getUser(did);
                liveLocation.id = did;
            } else {
                liveLocation.chat = MessagesController.getInstance(currentAccount).getChat(-did);
                liveLocation.id = did;
            }
        }

        try {
            MarkerOptions options = new MarkerOptions().position(latLng);
            Bitmap bitmap = createUserBitmap(liveLocation);
            if (bitmap != null) {
                options.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
                options.anchor(0.5f, 0.907f);
                liveLocation.marker = googleMap.addMarker(options);
                markers.add(liveLocation);
                markersMap.put(liveLocation.id, liveLocation);
                LocationController.SharingLocationInfo myInfo = LocationController.getInstance(currentAccount).getSharingLocationInfo(dialogId);
                if (liveLocation.id == UserConfig.getInstance(currentAccount).getClientUserId() && myInfo != null && liveLocation.object.id == myInfo.mid && myLocation != null) {
                    liveLocation.marker.setPosition(new LatLng(myLocation.getLatitude(), myLocation.getLongitude()));
                }
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        liveLocation.object = message;
        liveLocation.marker.setPosition(latLng);
    }
    return liveLocation;
}
 
Example 17
Source File: LocationActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private LiveLocation addUserMarker(TLRPC.Message message) {
    LiveLocation liveLocation;
    LatLng latLng = new LatLng(message.media.geo.lat, message.media.geo._long);
    if ((liveLocation = markersMap.get(message.from_id)) == null) {
        liveLocation = new LiveLocation();
        liveLocation.object = message;
        if (liveLocation.object.from_id != 0) {
            liveLocation.user = MessagesController.getInstance(currentAccount).getUser(liveLocation.object.from_id);
            liveLocation.id = liveLocation.object.from_id;
        } else {
            int did = (int) MessageObject.getDialogId(message);
            if (did > 0) {
                liveLocation.user = MessagesController.getInstance(currentAccount).getUser(did);
                liveLocation.id = did;
            } else {
                liveLocation.chat = MessagesController.getInstance(currentAccount).getChat(-did);
                liveLocation.id = did;
            }
        }

        try {
            MarkerOptions options = new MarkerOptions().position(latLng);
            Bitmap bitmap = createUserBitmap(liveLocation);
            if (bitmap != null) {
                options.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
                options.anchor(0.5f, 0.907f);
                liveLocation.marker = googleMap.addMarker(options);
                markers.add(liveLocation);
                markersMap.put(liveLocation.id, liveLocation);
                LocationController.SharingLocationInfo myInfo = LocationController.getInstance(currentAccount).getSharingLocationInfo(dialogId);
                if (liveLocation.id == UserConfig.getInstance(currentAccount).getClientUserId() && myInfo != null && liveLocation.object.id == myInfo.mid && myLocation != null) {
                    liveLocation.marker.setPosition(new LatLng(myLocation.getLatitude(), myLocation.getLongitude()));
                }
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        liveLocation.object = message;
        liveLocation.marker.setPosition(latLng);
    }
    return liveLocation;
}