我一直试图实现同样的,这正是我想要的: -
我已经实现googleMapView与覆盖,我有一个问题,我想显示弹出每个覆盖点击后,当我点击另一个叠加的previous popus应该会消失,新人们应该出现在单击位置(即投影点)。当我点击其他任何地方screen.Im使用中的onTap事件记录的onclick弹出不应该出现。 (map_overlay)是我想说明,当有人点击地图上的投影点的布局。在code是下方map_overlay.xml可能是任意文件。
类:ItemizedOverlay
公共布尔中的onTap(GeoPoint对象磷,图形页面图形页面){
LayoutInflater充气=(LayoutInflater)cContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
的LayoutParams LP =新MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT,P,LayoutParams.WRAP_CONTENT);
的LinearLayout视图=(的LinearLayout)inflater.inflate(R.layout.map_overlay,NULL);
mapView.removeView(视图);
mapView.invalidate();
mapView.addView(查看,LP);
mapView.invalidate();
返回true;
}
下面是主类中,即时通讯显示的投影点,这是工作的罚款,并即时致电我已经实现了活动的onTap另一个类如上图所示:
公共**类的MapView **扩展MapActivity {
私人的ArrayList< MyClass的> overlayItem;
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.large_mapview);
图形页面=(图形页面)findViewById(R.id.mapview);
// mapView.setBuiltInZoomControls(真正的);
名单<覆盖> mapOverlays =调用MapView.getOverlays();
可绘制绘制= this.getResources()getDrawable(R.drawable.mappointer2)。
ItemizedOverlay itemizedoverlay =新ItemizedOverlay(绘制,这一点);
OverlayItem overlayitem;
的GeoPoint点;
双纬度;
双LNG;
的for(int i = 0; I< overlayItem.size();我++){
纬度= Double.parseDouble(overlayItem.get(ⅰ).getLatitude());
液化天然气= Double.parseDouble(overlayItem.get(ⅰ).getLongitude());
点=新的GeoPoint((INT)(LAT * 1E6),(INT)(LNG * 1E6));
overlayitem =新OverlayItem(点,1 +的toString(),overlayItem.get(我).getDetails()的toString());
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
mapView.invalidate();
}
}
解决方案
查看 Android的mapviewballoons 的GitHub上。有一个ItemizedOverlay,你可以扩展,这是否确切的事情。我在我的几个应用程序使用它。
Ive been trying to acheive the same, this is exactly what i want :-
i have implemented googleMapView with overlays, i have one issue i want to show a popup when clicked on each overlay, and when i click on another overlay the previous popus should disappear and new one should appear at the clicked location(ie projection points). And popup shouldnt appear when i click anywhere else on screen.Im using onTap event to record onclick. (map_overlay) is the layout that i want to show when someone click a projection point on the map. The code is below and map_overlay.xml could be any file.
Class: ItemizedOverlay
public boolean onTap(GeoPoint p, MapView mapView) {
LayoutInflater inflater = (LayoutInflater)cContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutParams lp = new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, p, LayoutParams.WRAP_CONTENT);
LinearLayout view = (LinearLayout)inflater.inflate(R.layout.map_overlay, null);
mapView.removeView(view);
mapView.invalidate();
mapView.addView(view,lp);
mapView.invalidate();
return true;
}
Below is the Main class in which im displaying projection points which is working fine and im calling I have implemented the onTap event in another class as shown above:
public **class MapView** extends MapActivity{
private ArrayList<MyClass> overlayItem ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.large_mapview);
mapView = (MapView) findViewById(R.id.mapview);
// mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.mappointer2);
ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable,this);
OverlayItem overlayitem;
GeoPoint point;
double lat;
double lng;
for (int i = 0; i < overlayItem.size(); i++) {
lat = Double.parseDouble(overlayItem.get(i).getLatitude());
lng = Double.parseDouble(overlayItem.get(i).getLongitude());
point = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));
overlayitem = new OverlayItem(point, i+"".toString(), overlayItem.get(i).getDetails().toString());
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
mapView.invalidate();
}
}
解决方案
Check out Android-mapviewballoons on github. Has an ItemizedOverlay that you can extend that does this exact thing. I use it in several of my apps.