首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在nMap android studio中确定点颜色

在nMap android studio中确定点颜色
EN

Stack Overflow用户
提问于 2018-05-07 16:37:28
回答 1查看 35关注 0票数 0

我在一个android studio中创建了一个mMap标记项目,其中的数据使用json..which连接到数据库。我想问一下,如何使用以下术语指定颜色标记"if else“:

肯·肯·卡兰?

1

这是我的代码:

代码语言:javascript
复制
//GENERATE DATA MAP
            //Toast.makeText(getApplicationContext(), "Jumlah SIte Id X = "+SITE_ID.size(), Toast.LENGTH_LONG).show();
            for(int i = 0 ; i < SITE_ID.size() ; i++){

                Double lat = Double.parseDouble(LAT.get(i));
                Double longi = Double.parseDouble(LONG.get(i));

            BitmapDescriptor revicon = null;
              double Rev = Double.parseDouble(""+Rev_ALL_month3.get(i)) ;

                if( Rev >= 200000000) {
                    revicon = BitmapDescriptorFactory
                            .fromResource(R.drawable.merah);
                }
                    else if(Rev >= 100000000 && Rev <= 200000000) {
                    revicon = BitmapDescriptorFactory
                            .fromResource(R.drawable.kuning);
                }
                          else if(Rev >=60000000 && Rev <= 100000000) {
                    revicon = BitmapDescriptorFactory
                            .fromResource(R.drawable.biru);
                }
                                  else if(Rev >=30000000 && Rev <= 60000000) {
                    revicon = BitmapDescriptorFactory
                            .fromResource(R.drawable.hijau);
                }
                                      else if(Rev >= 30000000) {
                    revicon = BitmapDescriptorFactory
                            .fromResource(R.drawable.hitam);
                }



                mMap.addMarker(new MarkerOptions()
                        .position(new LatLng(lat,longi))
                        .title(SITE_ID.get(i))
                        .snippet("Data Handset 2G :" +"Des 2017("+Jml_Handset_2G_month1.get(i)+"), Jan 2018("+Jml_Handset_2G_month2.get(i)+"), Feb 2018("+Jml_Handset_2G_month3.get(i)+"), MoM("+Jml_Handset_2G_inc.get(i)+")\n\n"
                                +"Data Handset 3G :" +"Des 2018("+Jml_Handset_3G_month1.get(i)+"), Jan 2018("+Jml_Handset_3G_month2.get(i)+"), Feb 2018("+Jml_Handset_3G_month3.get(i)+"), MoM("+Jml_Handset_3G_inc.get(i)+")\n\n"
                                +"Data Handset 4G :" +"Des 2017("+Jml_Handset_4G_month1.get(i)+"), Jan 2018("+Jml_Handset_4G_month2.get(i)+"), Feb 2018("+Jml_Handset_4G_month3.get(i)+"), MoM("+Jml_Handset_4G_inc.get(i)+")\n\n"


                                +"Revenue Voice :" +"Des 2017("+Rev_Voice_month1.get(i)+"), Jan 2018("+Rev_Voice_month2.get(i)+"), Feb 2018("+Rev_Voice_month3.get(i)+"), MoM("+Rev_Voice_inc.get(i)+")\n\n"
                                +"Revenue SMS :" +"Des 2017("+Rev_SMS_month1.get(i)+"), Jan 2018("+Rev_SMS_month2.get(i)+"), Feb 2018("+Rev_SMS_month3.get(i)+"), MoM("+Rev_SMS_inc.get(i)+")\n\n"
                                +"Revenue Broadband :" +"Des 2017("+Rev_BBand_month1.get(i)+"), Jan 2018("+Rev_BBand_month2.get(i)+"), Feb 2018("+Rev_BBand_month3.get(i)+"), MoM("+Rev_BBand_inc.get(i)+")\n\n"
                                +"Revenue Digital :" +"Des 2017("+Rev_Digital_month1.get(i)+"), Jan 2018("+Rev_Digital_month2.get(i)+"), Feb 2018("+Rev_Digital_month3.get(i)+"), MoM("+Rev_Digital_inc.get(i)+")\n\n"
                                +"Revenue GSM :" +"Des 2017("+Rev_GSM_month1.get(i)+"), Jan 2018("+Rev_GSM_month2.get(i)+"), Feb 2018("+Rev_GSM_month3.get(i)+"), MoM("+Rev_GSM_inc.get(i)+")\n\n"
                                +"Revenue DCS :" +"Des 2017("+Rev_DCS_month1.get(i)+"), Jan 2018("+Rev_DCS_month2.get(i)+"), Feb 2018("+Rev_DCS_month3.get(i)+"), MoM("+Rev_DCS_inc.get(i)+")\n\n"
                                +"Revenue 3G :" +"Des 2017("+Rev_3G_month1.get(i)+"), Jan 2018("+Rev_3G_month2.get(i)+"), Feb 2018("+Rev_3G_month3.get(i)+"), MoM("+Rev_3G_inc.get(i)+")\n\n"
                                +"Revenue IR :" +"Des 2017("+Rev_IR_month1.get(i)+"), Jan 2018("+Rev_IR_month2.get(i)+"), Feb 2018("+Rev_IR_month3.get(i)+"), MoM("+Rev_IR_inc.get(i)+")\n\n"
                                +"Revenue ALL :" +"Des 2017("+Rev_ALL_month1.get(i)+"), Jan 2018("+Rev_ALL_month2.get(i)+"), Feb 2018("+Rev_ALL_month3.get(i)+"), MoM("+Rev_ALL_inc.get(i)+")\n"

                        )




                    .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.green)));

截图:

EN

回答 1

Stack Overflow用户

发布于 2018-05-09 09:09:49

一种建议是先预定义颜色

代码语言:javascript
复制
BitmapDescriptor green=
BitmapDescriptorFactory.fromResource(R.drawable.green); //etc etc


for(int i = 0 ; i < SITE_ID.size() ; i++){
    Double lat = Double.parseDouble(LAT.get(i));
    Double longi = Double.parseDouble(LONG.get(i));
    mMap.addMarker(new MarkerOptions()
                    .position(new LatLng(lat,longi))
                    .title(SITE_ID.get(i))
                    .snippet(" <SNIP... YOUR SNIPPET>" )
                    .icon( ( //ternary operator
                        rev >200_000_000 ? red: 
                        rev >100_000_000 ? yellow:
                        rev > 60_000_000 ? white:
                        rev > 30_000_000 ? green:
                        black  
                    ) );

三元运算符将选择要使用的正确bitmapDescriptor。

您还可以将三元运算符提取到它自己的方法中。

代码语言:javascript
复制
private BitmapDescriptor getColor(long rev){
  return  rev >200_000_000 ? red: 
   rev >100_000_000 ? yellow:
   rev > 60_000_000 ? white:
   rev > 30_000_000 ? green:
   black ;
}

然后使用以下命令调用该方法

代码语言:javascript
复制
    .icon (getColor(rev));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50210143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档