2017-07-05 22 views
0

有没有办法让我可以更改开始和结束标记的图标,如开始为蓝色,结束为红色,添加不同的细节并添加连接多段线?帮助Android地图标记更改开始和结束颜色,放置不同的细节并添加多段线

按钮:

b.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       for (int i = 0; i < list_location.size(); i++) { 
        createMarker(list_location.get(i).getLatitude(), list_location.get(i).getLongitude()); 
       } 
      } 
      }); 

标记:

private void createMarker(String latitude, String longitude) { 
    // Adding the taped point to the ArrayList 
    BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.ic_menu_camera); 
    Double lat = Double.parseDouble(latitude); 
    Double Longitude = Double.parseDouble(longitude); 

    map.addMarker(new MarkerOptions() 
      .position(new LatLng(lat, Longitude)) 
      .anchor(0.5f, 0.5f) 
      .title("title") 
      .snippet("snippet") 
      .icon(icon)); 

} 

回答

1

这很容易,但似乎你还没有尝试过多少

您可以使用索引来查找第一个和最后一个点 并绘制不同基于位置的颜色

for (int i = 0; i < list_location.size(); i++) { 
    createMarker(i, list_location.get(i).getLatitude(),list_location.get(i).getLongitude()); 
} 

,并在您createMarker()方法

private void createMarker(int index, String latitude, String longitude) { 
    // Adding the taped point to the ArrayList 
if (index == 0) 
color = BitmapDescriptorFactory.COLOR_THAT_SUITS; 
else if (index == list_location.size()-1) 
color = BitmapDescriptorFactory.COLOR_THAT_SUITS; 

//set this color to your marker 
..... 
..... 
.icon(BitmapDescriptorFactory.defaultMarker(color))); 

}

+0

你好,感谢你的回答。我期待着折线。谢谢。 – user8256287

+0

https://stackoverflow.com/a/25499892/1976626检查此答案可能有帮助... –

+0

嗨迈克尔Shrestha,你可以请。用我的代码启发我?谢谢。 – user8256287

相关问题