0

我正在做我的毕业论文,我必须做一个 Android 应用程序,它会在谷歌地图上显示我的位置(我已经做过),当我点击大学中的一些图钉时,会弹出一些建筑物的信息,如果我可以的话我单击它们,它们将重定向到一个 url。我已经用 Toast 完成了它,但它并没有满足我的需求。我已经搜索并发现 NooYawk 弹出。这是我的代码,如果有人可以提供帮助,我将不胜感激。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;
    }
    }
}

[更新]

弹出菜单的代码更多,但我不想显示 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);
  }
}
4

1 回答 1

0

尝试在您的位置上添加一个 OnTouchListener 并使用 Layout Inflator 显示带有您想要显示的信息的自定义布局。

于 2013-01-23T17:02:40.660 回答