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

The following examples show how to use com.google.android.gms.maps.model.MarkerOptions#icon() . 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: 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 2
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 3
Source File: PlacesDisplayTask.java    From Crimson with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(List<HashMap<String, String>> list) {
    googleMap.clear();

        for (int i = 0; i < list.size(); i++) {
            MarkerOptions markerOptions = new MarkerOptions();
            HashMap<String, String> googlePlace = list.get(i);
            double lat = Double.parseDouble(googlePlace.get("lat"));
            double lng = Double.parseDouble(googlePlace.get("lng"));
            String placeName = googlePlace.get("place_name");
            //String vicinity = googlePlace.get("vicinity");
            LatLng latLng = new LatLng(lat, lng);
            markerOptions.position(latLng);
            markerOptions.title(placeName);
            markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.custom_marker));
            googleMap.addMarker(markerOptions);
        }
    }
 
Example 4
Source File: GetNearbyPlacesData.java    From Krishi-Seva with MIT License 6 votes vote down vote up
private void ShowNearbyPlaces(List<HashMap<String, String>> nearbyPlacesList) {
    for (int i = 0; i < nearbyPlacesList.size(); i++) {
        Log.d("onPostExecute","Entered into showing locations");
        MarkerOptions markerOptions = new MarkerOptions();
        HashMap<String, String> googlePlace = nearbyPlacesList.get(i);
        double lat = Double.parseDouble(googlePlace.get("lat"));
        double lng = Double.parseDouble(googlePlace.get("lng"));
        String placeName = googlePlace.get("place_name");
        String vicinity = googlePlace.get("vicinity");
        LatLng latLng = new LatLng(lat, lng);
        markerOptions.position(latLng);
        markerOptions.title(placeName + " : " + vicinity);
        mMap.addMarker(markerOptions);
        markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
        //move map camera
        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
    }
}
 
Example 5
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 6
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {

    BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.mipmap.davidhackro);
    markerOptions.icon(icon);
    markerOptions.snippet(item.getTitle());
    markerOptions.title(item.getSubtitle());
    markerOptions.position(item.getPosition());


    super.onBeforeClusterItemRendered(item, markerOptions);
}
 
Example 7
Source File: MapFragment.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapClick(LatLng latLng) {

    MarkerOptions options = new MarkerOptions().position( latLng );
    options.title( getAddressFromLatLng( latLng ) );

    options.icon( BitmapDescriptorFactory.defaultMarker( ) );
    getMap().addMarker( options );
}
 
Example 8
Source File: PPTGoogleMapManager.java    From react-native-maps with MIT License 5 votes vote down vote up
/**
 * Places a colored default marker on the map at the required position.
 *
 * @param googleMap
 * @param latLng
 * @param hexColor
 */
private void markerWithColoredIcon(GoogleMap googleMap, LatLng latLng, String publicId, String hexColor)
{
    MarkerOptions options = new MarkerOptions();
    options.position(latLng);

    int color = Color.parseColor(hexColor);
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    float hue = hsv[0];
    options.icon(BitmapDescriptorFactory.defaultMarker(hue));

    Marker marker = googleMap.addMarker(options);
    publicMarkerIds.put(marker.getId(), publicId);
}
 
Example 9
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 10
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 11
Source File: MapsActivity.java    From Self-Driving-Car with MIT License 5 votes vote down vote up
@Override
    public void onLocationChanged(Location location) {


        mLastLocation = location;
        if (mCurrLocationMarker != null) {
            mCurrLocationMarker.remove();
        }

        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        Data data = new Data();
        data.setCurrentLocation(latLng);
        Log.e("Location", String.valueOf(location.getAccuracy()));
        data.setAltitude(location.getAltitude());

        //Place current location marker
        if (toSetMarker) {

            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.title("Current Position");
            markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
            mCurrLocationMarker = mMap.addMarker(markerOptions);
            markerPoints.add(latLng);


            //move map camera
            mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            mMap.animateCamera(CameraUpdateFactory.zoomTo(18));
        }
        toSetMarker = false;


//        //stop location updates
//        if (mGoogleApiClient != null) {
//            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
//        }

    }
 
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: MarkerOptionsChooser.java    From clusterkraf with Apache License 2.0 5 votes vote down vote up
@Override
public void choose(MarkerOptions markerOptions, ClusterPoint clusterPoint) {
	Host host = hostRef.get();
	if (host != null) {
		Bitmap bitmap = host.getIconBitmap(clusterPoint);
		markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
	}
}
 
Example 14
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 15
Source File: NearByHospitalActivity.java    From BloodBank with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
    lastlocation = location;
    LatLng latLng = new LatLng(location.getLatitude() , location.getLongitude());
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Current Location");
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
    currentLocationmMarker = mMap.addMarker(markerOptions);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    mMap.animateCamera(CameraUpdateFactory.zoomBy(0));

}
 
Example 16
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 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;
}
 
Example 18
Source File: CustomMarkerClusteringDemoActivity.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
@Override
protected void onBeforeClusterRendered(@NonNull Cluster<Person> cluster, MarkerOptions markerOptions) {
    // Draw multiple people.
    // Note: this method runs on the UI thread. Don't spend too much time in here (like in this example).
    markerOptions.icon(getClusterIcon(cluster));
}
 
Example 19
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 20
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Prepare the marker options for an observation point
 *
 * @param observation observation
 * @param visible     visible flag
 * @return marker options
 */
private MarkerOptions getMarkerOptions(Observation observation, boolean visible) {
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.icon(ObservationBitmapFactory.bitmapDescriptor(context, observation));
    markerOptions.visible(visible);
    return markerOptions;
}