使特定的图标标记在谷歌Android地图取决于类别从JSON [英] make specific icon marker depend on category from json in android google map
问题描述
我有一个问题,我想使图标标记不同的每个类别中,我有3个类别1.pendidikan,2 pariwisata 3. INDUSTRI,我想为pendidikan(图标hue_blue),pariwisata(hue_yellow)和INDUSTRI(hue_green)
这是源$ C $ C,我有
SupportMapFragment mapFrag =(SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。
地图= mapFrag.getMap();
peta.setMyLocationEnabled(真);
moveToMyLocation();
的for(int i = 0; I< dataArray.size();我++) { HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>(); 地图= dataArray.get(ⅰ); 经纬度tampilkanpetanya =新的经纬度(Double.parseDouble(map.get(tag_latitude)),Double.parseDouble(map.get(tag_longitude)));
的MarkerOptions =新的MarkerOptions();
markerOptions.position(tampilkanpetanya);
markerOptions.title(map.get(lokasi_id));
markerOptions.snippet(map.get(nama_lokasi));
//markerOptions.getAttribute(map.get(\"lokasi_id));
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
。cameraPosition =新CameraPosition.Builder()目标(tampilkanpetanya).zoom(12).build();
peta.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
peta.addMarker(的MarkerOptions);
peta.setMapType(GoogleMap.MAP_TYPE_HYBRID)
如何像这样(假设你的类别是一个字符串):
字符串类= ....的getCategory();
如果(category.equals(pariwisata)){
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
}否则如果(category.equals(pariwisata)){
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
}其他{
// Defaultcase
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
}
i have a problem, i want to make icon marker different each category, i have 3 category 1.pendidikan , 2. pariwisata 3. industri , and i want to make for pendidikan (icon hue_blue), pariwisata (hue_yellow) and industri (hue_green)
this is source code i have SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); peta = mapFrag.getMap();
peta.setMyLocationEnabled(true);
moveToMyLocation();
for (int i = 0; i < dataArray.size(); i++)
{
HashMap<String, String> map = new HashMap<String, String>();
map = dataArray.get(i);
LatLng tampilkanpetanya = new LatLng(Double.parseDouble(map.get(tag_latitude)),Double.parseDouble(map.get(tag_longitude)));
markerOptions = new MarkerOptions();
markerOptions.position(tampilkanpetanya);
markerOptions.title(map.get("lokasi_id"));
markerOptions.snippet(map.get("nama_lokasi"));
//markerOptions.getAttribute(map.get("lokasi_id"));
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
cameraPosition = new CameraPosition.Builder().target(tampilkanpetanya).zoom(12).build();
peta.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
peta.addMarker(markerOptions);
peta.setMapType(GoogleMap.MAP_TYPE_HYBRID)
How about something like this (assuming your category is a string):
String category = ....getCategory();
if(category.equals("pariwisata")) {
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
} else if(category.equals("pariwisata")) {
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
} else {
// Defaultcase
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
}
这篇关于使特定的图标标记在谷歌Android地图取决于类别从JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!