41

What color is available to make a marker on Android map?
How many colors are there and how to write the code of color?

JJD
  • 50,076
  • 60
  • 203
  • 339
kucluk
  • 540
  • 2
  • 9
  • 29

5 Answers5

81

Here is a method I am using to generate dynamic Hue colors for markers based on given String color.

May be useful for someone :)

Marker melbourne = mMap.addMarker(new MarkerOptions().position(MELBOURNE)
.icon(getMarkerIcon("#ff2299")));

// method definition
public BitmapDescriptor getMarkerIcon(String color) {
    float[] hsv = new float[3];
    Color.colorToHSV(Color.parseColor(color), hsv);
    return BitmapDescriptorFactory.defaultMarker(hsv[0]);
}
user1732111
  • 56
  • 1
  • 6
S.Thiongane
  • 6,883
  • 3
  • 37
  • 52
  • 10
    but it creating light color and actual color is darker – Zaid Mirza Jan 22 '18 at 12:17
  • Isn't this just mapping the custom string colour to the nearest default map marker colour? So if you put in a very dark green string (e.g. 001C00) it'll just map it to the standard light green (HUE_GREEN) – JMax Mar 30 '22 at 16:10
69

This is how to make a default marker

Marker melbourne = mMap.addMarker(new MarkerOptions().position(MELBOURNE)
    .icon(BitmapDescriptorFactory
        .defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

and these are the constants you can use

float   HUE_AZURE   
float   HUE_BLUE    
float   HUE_CYAN    
float   HUE_GREEN   
float   HUE_MAGENTA 
float   HUE_ORANGE  
float   HUE_RED 
float   HUE_ROSE    
float   HUE_VIOLET  
float   HUE_YELLOW
JJD
  • 50,076
  • 60
  • 203
  • 339
JRowan
  • 6,824
  • 8
  • 40
  • 59
  • thats what is says https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory – JRowan Sep 29 '13 at 09:02
  • 3
    Those are just a few predefined hues. Since the `defaultMarker()` method takes a `float`, you can supply any value within a range of `[0...360]`. – MH. Sep 29 '13 at 09:29
  • im not really sure did you try 360? – JRowan Apr 02 '14 at 22:01
  • 6
    If it is from 0 to 360, which one is grey? – sunlover3 May 09 '16 at 07:59
  • 4
    According to Google Maps Android SDK's documentation, only hue can be used to color a marker `BitmapDescriptorFactory.defaultMarker(float hue)`. How can one get a proper color by considering only hue out of HSV? Either Google has badly implemented the coloring functionality or I am gravely mistaken. I really hope it is not the former. It is such a pain either way! – Lingaraju E V Mar 02 '19 at 21:10
  • 1
    @sunlover3 there's no grey hue value in the HSB/HSL encodings of RGB – Leonardo Sibela Jun 20 '19 at 20:23
15

DETAILED ANSWER!

float hue = 120;  //(Range: 0 to 360)

Marker melbourne = mMap.addMarker(new MarkerOptions().position(MELBOURNE)
    .icon(BitmapDescriptorFactory
        .defaultMarker(hue)));

You can give any hue value ranging from 0 to 360, some constants are defined here (https://developers.google.com/android/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory)

BEST WAY! to find required hue(that matches your required color).

Open this image defult_pin in Paint.Net/Photoshop editor (or other)

Goto hue options in your photo editor and slide hue bar and note best matched hue value.

  • For Paint.net (Adjustments -> Hue/Saturation)

  • For Photoshop (Photography -> Adjustments -> Hue/Saturation)

if value is above 0, use exact value , if value is below 0, take postivie (absolute) of value, add it in 180 and use the result value.

enter image description here

SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
Farhan
  • 3,162
  • 3
  • 25
  • 17
  • There is an ancient tool called GetColor. I still use this today! Check it out. http://www.wincatalog.com/getcolor.html – Steven Hammons Jul 14 '17 at 18:17
  • The formula for *negative* hue which worked for me is `360 + x`, where `x` is the hue I want (and is negative). For example, I want hue -120, then the formula gives me `360 + (-120) = 240`. When a hue is positive, it's simply the hue. – Hawklike May 20 '22 at 09:17
1

Symbol You Want on Color You Want!

I was looking for this answer for days and here it is the right and easy way to create a custom marker:

'http://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=xxx%7c5680FC%7c000000&.png' where xxx is the text and 5680fc is the hexadecimal color code and 000000 is the hexadecimal color code of the text.

Theses markers are totally dynamic and you can create whatever balloon icon you want. Just change the URL.

Paolo177
  • 366
  • 6
  • 18
1

Simple explanation that no one mentioned yet:

When you set marker color, you in fact set the x value of HSV(x, 100%, 100%)

  • Open any HEX/RGB-to-HSV converter, online version here
  • Convert your HEX/RGB to HSV
  • (H)ue is the x value you use in BitmapDescriptorFactory.defaultMarker(x)
  • (S)aturation will be set to 100% by Google Maps API
  • (V)alue will be set to 100% by Google Maps API

The above also means that you can't set any marker color you wish this way. To represent any color as HSV, (S) and (V) should also be altered but Google Maps API doesn't allow this for the default marker - it uses constant value "100%".

If you want to see how your marker will look like, open any HSV converter (online version here), set (H)ue to the x value you got above, (S)aturation and (V)alue to 100%.

NOTE: alternatively, instead of HSV(x, 100%, 100%) you may use HSL(x, 100%, 50%) which encodes exactly the same color.

dominik
  • 2,404
  • 2
  • 29
  • 33