我尝试使用自定义标记图标(位图和文本视图)为1800个项目创建地图。由于我的应用程序在创建一些标记后关闭,因此导致内存不足。 我该怎么做? 这是我的代码的一部分我的代码: 谢谢大家!再见
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE)
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setCompassEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
mMap.getUiSettings().setRotateGesturesEnabled(true);
mMap.getUiSettings().setScrollGesturesEnabled(true);
mMap.getUiSettings().setTiltGesturesEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
mMap.setMyLocationEnabled(true);
start();
}
public void start() {
new BackgroundTask().execute();
}
private class BackgroundTask extends AsyncTask<Void, Integer, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progress.setProgress(0);
progress.setMessage("Loading");
progress.show();
cursor.moveToFirst();
}
@Override
protected String doInBackground(Void... arg0) {
try {
if (cursor.moveToFirst())
{
do {
nome = cursor.getString(cursor.getColumnIndex(LocalDbManage.KEY_NOME));
lati = cursor.getString(cursor.getColumnIndex(LocalDbManage.KEY_LATI));
longi = cursor.getString(cursor.getColumnIndex(LocalDbManage.KEY_LONGI));
prezzo = "€ "+cursor.getString(cursor.getColumnIndex(LocalDbManage.KEY_PREZZO));
id = cursor.getString(cursor.getColumnIndex(LocalDbManage.KEY_CONTACTID));
final double latitude = Double.parseDouble(lati);
final double longitude = Double.parseDouble(longi);
iconFactory.setRotation(90);
iconFactory.setStyle(IconGenerator.STYLE_ORANGE);
addIcon(iconFactory, prezzo, new LatLng(latitude, longitude));
runOnUiThread(new Runnable() {
@Override
public void run() {
final MarkerOptions markerOptions = new MarkerOptions().
icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon())).
position(new LatLng(latitude, longitude)).
anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());
mMap.addMarker(markerOptions);
}
});
} while (cursor.moveToNext());
} else
{
System.out.println("ERROR"); // viene eseguito l'else
}
Thread.sleep(1200);
} catch (InterruptedException e) {
}
return "Lavoro Terminato!";
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progress.dismiss();
}
}
private void addIcon(IconGenerator iconFactory,String text, LatLng position) {
MarkerOptions markerOptions = new MarkerOptions().
icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon())).
position(position).
anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV())`
}
编辑:现在我开始了#34;无法将位图复制到parcel blob&#34;我不知道这意味着什么..请帮助我! 感谢&#39; S