【发布时间】:2015-05-23 06:18:30
【问题描述】:
我有这个活动:
public class MapActivity extends FragmentActivity {
private GoogleMap mMap;
private ClusterManager<GasStationItem> mClusterManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_gas_station);
try {
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
mMap.setMyLocationEnabled(true);
setUpClusters();
}
} catch (NullPointerException e){
e.printStackTrace();
}
}
private void setUpClusters(){
mClusterManager = new ClusterManager<GasStationItem>(this, mMap);
mMap.setOnCameraChangeListener(mClusterManager);
mMap.setOnMarkerClickListener(mClusterManager);
mClusterManager.setRenderer(new OwnIconRendered(this ,mMap ,mClusterManager));
addItems();
}
private void addItems(){
ParseQuery<GasStationItem> query = ParseQuery.getQuery(GasStationItem.class);
query.setLimit(100);
query.findInBackground(new FindCallback<GasStationItem>() {
@Override
public void done(List<GasStationItem> gasStationItems, ParseException e) {
if (e == null) {
for (int i=0; i< gasStationItems.size(); i++){
GasStationItem gasStationItem = gasStationItems.get(i);
mClusterManager.addItem(gasStationItem);
}
} else {
Log.d("ERROR:", "" + e.getMessage());
}
}
});
}
class OwnIconRendered extends DefaultClusterRenderer<GasStationItem> {
private BitmapDescriptor mBitmapMarker;
public OwnIconRendered(Context context, GoogleMap map,
ClusterManager<GasStationItem> clusterManager) {
super(context, map, clusterManager);
}
@Override
protected void onBeforeClusterItemRendered(GasStationItem item, MarkerOptions markerOptions) {
mBitmapMarker = customizeMarkers(item.getName());
markerOptions.icon(mBitmapMarker);
markerOptions.title(item.getName());
super.onBeforeClusterItemRendered(item, markerOptions);
}
}
private BitmapDescriptor customizeMarkers(String input){
BitmapDescriptor bitmapMarker = BitmapDescriptorFactory.fromResource(R.mipmap.ic_launcher);
if(input.contains("Gazprom")){
bitmapMarker = BitmapDescriptorFactory.fromResource(R.mipmap.gazprom);
} else {
if(input.contains("Mol")) {
bitmapMarker = BitmapDescriptorFactory.fromResource(R.mipmap.mol);
} else {
if(input.contains("Petrom")){
bitmapMarker = BitmapDescriptorFactory.fromResource(R.mipmap.petrom);
} else {
if(input.contains("OMV")){
bitmapMarker = BitmapDescriptorFactory.fromResource(R.mipmap.omv);
} else {
if(input.contains("Lukoil")){
bitmapMarker = BitmapDescriptorFactory.fromResource(R.mipmap.lukoil);
} else {
if(input.contains("Rompetrol")){
bitmapMarker = BitmapDescriptorFactory.fromResource(R.mipmap.rompetrol);
}
}
}
}
}
}
return bitmapMarker;
}
}
LatLng 用于标记我从数据库中读取它,我为此使用解析。我还覆盖 Renderer 来自定义我的标记。
当我启动活动时,甚至没有绘制地图。我认为是相对的来自 logcat 的单个错误是:
03-20 00:31:51.425 1996-1996/com.driverbuddy.costeiu.driverbuddy I/Choreographer:跳过33帧!该应用程序可能也在做 在它的主线程上做了很多工作。
【问题讨论】:
标签: android google-maps google-maps-markers markerclusterer