Android map marker color?
Asked Answered
A

5

42

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

Adalia answered 29/9, 2013 at 8:50 Comment(0)
C
72

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
Console answered 29/9, 2013 at 9:0 Comment(6)
thats what is says developers.google.com/maps/documentation/android/reference/com/…Console
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].Totalitarianism
im not really sure did you try 360?Console
If it is from 0 to 360, which one is grey?Martens
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!Fussy
@Martens there's no grey hue value in the HSB/HSL encodings of RGBZareba
A
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]);
}
Autotomize answered 9/10, 2015 at 10:55 Comment(2)
but it creating light color and actual color is darkerQumran
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)Karlee
C
72

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
Console answered 29/9, 2013 at 9:0 Comment(6)
thats what is says developers.google.com/maps/documentation/android/reference/com/…Console
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].Totalitarianism
im not really sure did you try 360?Console
If it is from 0 to 360, which one is grey?Martens
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!Fussy
@Martens there's no grey hue value in the HSB/HSL encodings of RGBZareba
G
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

Gateshead answered 11/7, 2015 at 13:33 Comment(2)
There is an ancient tool called GetColor. I still use this today! Check it out. wincatalog.com/getcolor.htmlLona
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.Dipterous
P
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.

Priscilapriscilla answered 29/12, 2017 at 11:46 Comment(0)
W
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.

Whitening answered 23/5, 2020 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.