请帮帮我,我正在开发一个带有mapView的Project Xyz,添加多个叠加层并根据userChoice删除叠加层。
更清楚的是,它根据用户选择,,,,
过滤叠加层假设显示最喜欢的地方,用户的朋友......
PostLoginServiceHomeBean是我的ArrayList,带有ArrayList NearByFavoritePlacesList对象
entry.getNearByFavoritePlacesList()。得到(ⅰ).getGpsLatitude() .trim()
即通过这个我得到多个lat长格式服务器......
代码运行f9并将多个叠加层添加到我的地图中,并在叠加层上显示相应位置的名称和地址。但是如何从地图中删除叠加层...
我随附代码:请找到以下代码:
请帮帮我....
package com.gogozing.app;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;
import com.gogozing.service.LocateServices;
import com.gogozing.util.Data;
import com.gogozing.util.PostLoginServiceHomeBean;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class HomeMapActivity extends MapActivity {
private MapView myMapView;
private MapController myMapController;
private List<Overlay> mapOverlays;
private HomeMapItemizedOverlay itemizedOverlay;
private Context context;
private PostLoginServiceHomeBean entry;
private GeoPoint initGeoPoint;
private CheckBox peopleCheckBox, friendsCheckBox, favoritesCheckBox;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_map_layout);
context = this;
backButton = (Button) findViewById(R.id.HomeMapLeftBackButton);
eventsBtn = (Button) findViewById(R.id.EventsBtn);
profileBtn = (Button) findViewById(R.id.ProflieBtn);
homeBtn = (Button) findViewById(R.id.HomeBtn);
locateButton = (Button) findViewById(R.id.LocateBtn);
socializeButton = (Button) findViewById(R.id.SocializeBtn);
peopleCheckBox = (CheckBox) findViewById(R.id.HomeMapViewPeopleCheckBox);
favoritesCheckBox = (CheckBox) findViewById(R.id.HomeMapViewFavoritesCheckBox);
friendsCheckBox = (CheckBox) findViewById(R.id.HomeMapViewFriendsCheckBox);
homeBtn.setBackgroundResource(R.drawable.home_f);
myMapView = (MapView) findViewById(R.id.mapviewHome);
myMapView.setBuiltInZoomControls(true);
// Set satellite view
myMapController = myMapView.getController();
// Get the current location in start-up
try {
entry = Data.postLoginServiceHomeMain.get(0);
favoritesCheckBox
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
viewFavoritePlaces();
} else
removeFavoritePlaces();
}
});
} catch (Exception e) {
Log.e(Data.LOG, e.getMessage(), e);
}
}
void viewFavoritePlaces() {
for (int i = 0; i < entry.getNearByFavoritePlacesList().size(); i++) {
double latitude = Double.valueOf(
**entry.getNearByFavoritePlacesList().get(i).getGpsLatitude()
.trim()**).doubleValue();
double longitude = Double.valueOf(
entry.getNearByFavoritePlacesList().get(i)
.getGpsLongitude().trim()).doubleValue();
Log.v(Data.LOG1, " Latitude " + latitude + " Longitude "
+ longitude);
String name = entry.getNearByFavoritePlacesList().get(i)
.getMerchantName();
String address = entry.getNearByFavoritePlacesList().get(i)
.getAddress();
initGeoPoint = new GeoPoint((int) (latitude * 1E6),
(int) (longitude * 1E6));
mapOverlays = myMapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(
R.drawable.map_store_place);
itemizedOverlay = new HomeMapItemizedOverlay(drawable, this);
OverlayItem overlayItem = new OverlayItem(initGeoPoint, name,
address);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
myMapController.animateTo(initGeoPoint);
myMapController.setZoom(15);
}
}
void removeFavoritePlaces() {
//List<Overlay> mapOverlays = myMapView.getOverlays();
mapOverlays.remove(itemizedOverlay);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
};
public class HomeMapItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public HomeMapItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
public void removeOverlay(OverlayItem overlay)
{
mOverlays.remove(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
}
答案 0 :(得分:2)
这里我给出了一个解决方案,我从你的问题中得到了...你需要将Lat Long添加到来自服务器的Overlay项目中并将其添加到逐项覆盖,之后你想要删除任何具有特定纬度的Itemized覆盖,您也可以检查并从地图覆盖中删除。