简体   繁体   English

在Google Map Application上弹出Android菜单

[英]Pop up menu android on google map application

I am doing my graduation thesis and I have to do an Android application which shows my location on Google Maps (something I have done), and when I click some pins in the university will pop up some informations for the buildings and if I could when i click them they will redirect to a url.I have done it with Toast but it doesn't fullfill my needs.I have searched and found NooYawk pop up.Here is my code if anyone can help I will be grateful. 我正在做毕业论文,我必须做一个Android应用程序,该程序在Google Maps上显示我的位置(我已经完成了此操作),当我单击大学中的一些图钉时,将会弹出一些建筑物信息,如果可以的话,我单击它们,它们将重定向到url。我已经用Toast完成了它,但没有满足我的需要。我已经搜索并发现NooYawk弹出了。如果有人可以帮助我,这是我的代码,我将不胜感激。 Ps I am amateur ps我很业余

public class TGpsActivity extends MapActivity {

 MapView mapView=null;
 MapController mapController=null;
 MyLocationOverlay whereAmI=null;

 @Override
 protected boolean isLocationDisplayed(){
        return whereAmI.isMyLocationEnabled();
 }

 @Override
 protected boolean isRouteDisplayed(){
     return true;
 }



public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    Drawable marker=getResources().getDrawable(R.drawable.pushpin);
    marker.setBounds((int) (-marker.getIntrinsicWidth()/2),-marker.getIntrinsicHeight(),(int) (marker.getIntrinsicWidth()/2),0);        
    mapController=mapView.getController();
    mapController.setZoom(15);

    InterestingLocations funPlaces= new InterestingLocations(marker);
    mapView.getOverlays().add(funPlaces);

    GeoPoint pt=funPlaces.getCenterPt();
    int latSpan=funPlaces.getLatSpanE6();
    int lonSpan=funPlaces.getLonSpanE6();
    Log.v("Overlays", "Lat span is " + latSpan);
    Log.v("Overlays", "Lon span is " + lonSpan);

    MapController mc = mapView.getController();
    mc.setCenter(pt);
    mc.zoomToSpan((int) (latSpan*1.5), (int)(lonSpan*1.5));


    whereAmI= new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(whereAmI);
    mapView.postInvalidate();

}
public class InterestingLocations extends ItemizedOverlay{
    private ArrayList<OverlayItem> locations = new ArrayList<OverlayItem>();
    private GeoPoint center=null;

    public InterestingLocations(Drawable marker){
        super(marker);

        GeoPoint headOffice = new GeoPoint((int)(37.97897823618044*1000000) ,(int)(23.6723855137825*1000000));
        GeoPoint computerRoom= new GeoPoint((int)(37.98013047446126*1000000) ,(int)(13.6715030670166*1000000));
        locations.add(new OverlayItem(headOffice,"headOffice","headOffice"));
        locations.add(new OverlayItem(computerRoom,"computerRoom","computerRoom"));

        populate();
    }

    public GeoPoint getCenterPt(){
        if(center==null){
            int northEdge= -90000000;
            int southEdge=  90000000;
            int eastEdge=  -180000000;
            int westEdge=   180000000;
            Iterator<OverlayItem> iter=locations.iterator();
            while(iter.hasNext()){
                GeoPoint pt=iter.next().getPoint();
                if(pt.getLatitudeE6() > northEdge)
                    northEdge=pt.getLatitudeE6();
                if(pt.getLatitudeE6() < southEdge)
                    southEdge=pt.getLatitudeE6();
                if(pt.getLongitudeE6() > eastEdge)
                    eastEdge=pt.getLongitudeE6();
                if(pt.getLongitudeE6() < westEdge)
                    westEdge=pt.getLongitudeE6();
            }
            center=new GeoPoint((int)((northEdge+southEdge)/2),(int)((westEdge+eastEdge)/2));

        }
        return center;
    }



@Override

public void draw(Canvas canvas, MapView mapView,boolean shadow)
{
        super.draw(canvas, mapView, shadow);
}
@Override
protected OverlayItem createItem(int i){
    return locations.get(i);
}
@Override
public int size() {

    return locations.size();

}

 @Override
    protected boolean onTap(int i) {
      Toast.makeText(TGpsActivity.this,
                      locations.get(i).getSnippet(),
                      Toast.LENGTH_LONG).show();

      return(true);
    }

}
@Override
public void onResume(){
    super.onResume();
    whereAmI.enableMyLocation();
    whereAmI.runOnFirstFix(new Runnable(){
            public void run(){
                    mapController.setCenter(whereAmI.getMyLocation());
            }
    });
}
@Override
public void onPause(){
        super.onPause();
        whereAmI.disableMyLocation();

}
public void myClickHandler(View target){
    switch(target.getId()){
    case R.id.sat:
        mapView.setSatellite(true);
        break;
    case R.id.traffic:
        mapView.setTraffic(true);
        break;
    case R.id.normal:
        mapView.setSatellite(false);
        mapView.setTraffic(false);
        break;
    }
    }
}

[update] [更新]

Something more the code for pop up menu is this but i dont want to show the l 弹出菜单的更多代码是这个,但我不想显示l

@Override
protected boolean onTap(int i) {
  OverlayItem item=getItem(i);
  GeoPoint geo=item.getPoint();
  Point pt=map.getProjection().toPixels(geo, null);

  View view=panel.getView();

  ((TextView)view.findViewById(R.id.latitude))
    .setText(String.valueOf(geo.getLatitudeE6()/1000000.0));
  ((TextView)view.findViewById(R.id.longitude))
    .setText(String.valueOf(geo.getLongitudeE6()/1000000.0));
  ((TextView)view.findViewById(R.id.x))
                          .setText(String.valueOf(pt.x));
  ((TextView)view.findViewById(R.id.y))
                          .setText(String.valueOf(pt.y));

  panel.show(pt.y*2>map.getHeight());

  return(true);
}

@Override
public int size() {
  return(items.size());}}
class PopupPanel {
View popup;
boolean isVisible=false;

PopupPanel(int layout) {
  ViewGroup parent=(ViewGroup)map.getParent();

  popup=getLayoutInflater().inflate(layout, parent, false);

  popup.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
      hide();
    }
  });
}

View getView() {
  return(popup);
}

void show(boolean alignTop) {
  RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(
        RelativeLayout.LayoutParams.WRAP_CONTENT,
        RelativeLayout.LayoutParams.WRAP_CONTENT
  );

  if (alignTop) {
    lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    lp.setMargins(0, 20, 0, 0);
  }
  else {
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lp.setMargins(0, 0, 0, 60);
  }

  hide();

  ((ViewGroup)map.getParent()).addView(popup, lp);
  isVisible=true;
}

void hide() {
  if (isVisible) {
    isVisible=false;
    ((ViewGroup)popup.getParent()).removeView(popup);
  }
}

尝试在您的位置上添加OnTouchListener并使用Layout Inflator来显示包含您要显示的信息的自定义布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM