最近在做毕设,主要实现的功能就是在地图上的气泡窗口里进行点击操作,有没有哪位牛人也是弄这块的?能给点思路吗?我现在想实现的功能是点击一个气泡里的按钮可以弹出另一个气泡 可是只能显示一个气泡窗口,没有办法再在mapView里面再加第二个气泡窗口,请大牛帮帮忙啊!我写的部分代码如下:显示地图的main activity代码:public class bubbleMap extends MapActivity {
protected Location location;
private MapController controller;
private MyLocationOverlay myLocation;
private LocationManager lm;
private MapView mapView;
private int intZoomLevel = 0;
private GeoPoint geoPoint;
private Drawable drawable, bubbleBackground;
protected static double latitude, longitude;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*地图初始化,定义controller及manager*/
mapView = (MapView)findViewById(R.id.myMapView1);
mapView.setStreetView(true);
mapView.setClickable(true);
controller = mapView.getController();
intZoomLevel = 15;
controller.setZoom(intZoomLevel);
lm =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
/* 获取当前的location*/
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW); String provider = lm.getBestProvider(criteria,true);
Location location = lm.getLastKnownLocation(provider);
geoPoint = updateWithNewLocation(location);
lm.requestLocationUpdates(provider, 500, 10, locationListener);
drawable = this.getResources().getDrawable(R.drawable.maritime);
bubbleBackground = this.getResources().getDrawable(R.drawable.bubble_background);
/*定义地图上的overlay*/
PopOverlay pop = new PopOverlay(this,drawable);
BubbleOverlay bubble = new BubbleOverlay(bubbleBackground,this,geoPoint,mapView/*,popView,introView*/);
OverlayItem item1 = new OverlayItem(geoPoint,"dalian Maritime University",
"I'm standing at DMU");
bubble.addOverlay(item1);
List<Overlay>overlays = mapView.getOverlays();
myLocation = new MyLocationOverlay(this,mapView);
myLocation.enableMyLocation();
myLocation.enableCompass();
overlays.add(myLocation);
overlays.add(pop);
overlays.add(bubble);
mapView.postInvalidate();
}
/*//////////////////
*//////////// 以下是自己定义的方法*/
private final LocationListener locationListener = new LocationListener(){
public void onLocationChanged(String provider){
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnavled(String probider){
}
public void onStatusChanged(String provider,int status,Bundle extras){}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
};
private GeoPoint updateWithNewLocation(Location location) {
// TODO Auto-generated method stub
String latLongString;
TextView myLocationText;
GeoPoint gp = null;
myLocationText = (TextView)findViewById(R.id.myLocationText);
if (location != null){
double lat = location.getLatitude();
double lng = location.getLongitude();
latitude = lat*1E6;
longitude = lng*1E6;
latLongString = "纬度:" + lat +"\n经度" + lng;
gp = new GeoPoint((int)latitude, (int)longitude);
controller.animateTo(gp);
}else {
latLongString = "无法获取地理信息";
}
myLocationText.setText("您当前的位置是:\n" + latLongString);
return gp;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}PopOverlay没有问题,BubbleOverlay有很大问题!!BubbleOverlay的代码:public class BubbleOverlay extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
private GeoPoint gPoint;
private MapView mView;
public BubbleOverlay(Drawable defaultMarker,Context context,GeoPoint gp,MapView c) {
super(defaultMarker);
mContext = context;
// TODO Auto-generated constructor stub
this.gPoint=gp;
this.mView=c;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mOverlays.get(i);
} @Override
public int size() {
// TODO Auto-generated method stub
return mOverlays.size();
}
@Override
protected boolean onTap(int index)
{
OverlayItem item = mOverlays.get(index);
final View popView = View.inflate(mContext, R.layout.overlay_pop, null);
mView.addView(popView, new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, gPoint, MapView.LayoutParams.BOTTOM_CENTER));
popView.setVisibility(View.GONE);
Double lng=126.676530486*1E6;
Double lat=45.7698895661*1E6;
GeoPoint gp= new GeoPoint(lat.intValue(),lng.intValue());
final View introView = View.inflate(mContext, R.layout.pop_intros, null);
mView.addView(introView, new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, gp, MapView.LayoutParams.LEFT));
introView.setVisibility(View.GONE);
popView.setVisibility(View.VISIBLE);
/* 实现关闭窗口*/
Button bClose= (Button) popView.findViewById(R.id.bubble_close);
bClose.setOnClickListener(new OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
popView.setVisibility(View.GONE);
}
});
/*实现跳转到intros页面*/
Button bIntros= (Button) popView.findViewById(R.id.intros);
bIntros.setOnClickListener(new OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
introView.setVisibility(View.VISIBLE);
}
});
Toast toast =Toast.makeText(mContext, item.getSnippet(), Toast.LENGTH_SHORT);
toast.show();
return true;
}
}
请各位大牛帮帮忙啊~我是真的快抓狂了....
protected Location location;
private MapController controller;
private MyLocationOverlay myLocation;
private LocationManager lm;
private MapView mapView;
private int intZoomLevel = 0;
private GeoPoint geoPoint;
private Drawable drawable, bubbleBackground;
protected static double latitude, longitude;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*地图初始化,定义controller及manager*/
mapView = (MapView)findViewById(R.id.myMapView1);
mapView.setStreetView(true);
mapView.setClickable(true);
controller = mapView.getController();
intZoomLevel = 15;
controller.setZoom(intZoomLevel);
lm =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
/* 获取当前的location*/
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW); String provider = lm.getBestProvider(criteria,true);
Location location = lm.getLastKnownLocation(provider);
geoPoint = updateWithNewLocation(location);
lm.requestLocationUpdates(provider, 500, 10, locationListener);
drawable = this.getResources().getDrawable(R.drawable.maritime);
bubbleBackground = this.getResources().getDrawable(R.drawable.bubble_background);
/*定义地图上的overlay*/
PopOverlay pop = new PopOverlay(this,drawable);
BubbleOverlay bubble = new BubbleOverlay(bubbleBackground,this,geoPoint,mapView/*,popView,introView*/);
OverlayItem item1 = new OverlayItem(geoPoint,"dalian Maritime University",
"I'm standing at DMU");
bubble.addOverlay(item1);
List<Overlay>overlays = mapView.getOverlays();
myLocation = new MyLocationOverlay(this,mapView);
myLocation.enableMyLocation();
myLocation.enableCompass();
overlays.add(myLocation);
overlays.add(pop);
overlays.add(bubble);
mapView.postInvalidate();
}
/*//////////////////
*//////////// 以下是自己定义的方法*/
private final LocationListener locationListener = new LocationListener(){
public void onLocationChanged(String provider){
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnavled(String probider){
}
public void onStatusChanged(String provider,int status,Bundle extras){}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
};
private GeoPoint updateWithNewLocation(Location location) {
// TODO Auto-generated method stub
String latLongString;
TextView myLocationText;
GeoPoint gp = null;
myLocationText = (TextView)findViewById(R.id.myLocationText);
if (location != null){
double lat = location.getLatitude();
double lng = location.getLongitude();
latitude = lat*1E6;
longitude = lng*1E6;
latLongString = "纬度:" + lat +"\n经度" + lng;
gp = new GeoPoint((int)latitude, (int)longitude);
controller.animateTo(gp);
}else {
latLongString = "无法获取地理信息";
}
myLocationText.setText("您当前的位置是:\n" + latLongString);
return gp;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}PopOverlay没有问题,BubbleOverlay有很大问题!!BubbleOverlay的代码:public class BubbleOverlay extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
private GeoPoint gPoint;
private MapView mView;
public BubbleOverlay(Drawable defaultMarker,Context context,GeoPoint gp,MapView c) {
super(defaultMarker);
mContext = context;
// TODO Auto-generated constructor stub
this.gPoint=gp;
this.mView=c;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mOverlays.get(i);
} @Override
public int size() {
// TODO Auto-generated method stub
return mOverlays.size();
}
@Override
protected boolean onTap(int index)
{
OverlayItem item = mOverlays.get(index);
final View popView = View.inflate(mContext, R.layout.overlay_pop, null);
mView.addView(popView, new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, gPoint, MapView.LayoutParams.BOTTOM_CENTER));
popView.setVisibility(View.GONE);
Double lng=126.676530486*1E6;
Double lat=45.7698895661*1E6;
GeoPoint gp= new GeoPoint(lat.intValue(),lng.intValue());
final View introView = View.inflate(mContext, R.layout.pop_intros, null);
mView.addView(introView, new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, gp, MapView.LayoutParams.LEFT));
introView.setVisibility(View.GONE);
popView.setVisibility(View.VISIBLE);
/* 实现关闭窗口*/
Button bClose= (Button) popView.findViewById(R.id.bubble_close);
bClose.setOnClickListener(new OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
popView.setVisibility(View.GONE);
}
});
/*实现跳转到intros页面*/
Button bIntros= (Button) popView.findViewById(R.id.intros);
bIntros.setOnClickListener(new OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
introView.setVisibility(View.VISIBLE);
}
});
Toast toast =Toast.makeText(mContext, item.getSnippet(), Toast.LENGTH_SHORT);
toast.show();
return true;
}
}
请各位大牛帮帮忙啊~我是真的快抓狂了....
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货