如何在mapfragment中添加additemizedoverlay?

时间:2013-04-28 14:35:53

标签: android overlay android-mapview mapfragment

我如何在additemizedoverlaymapfragment

此代码来自androidhive google places,我遇到mapview问题。它只显示可能由弃用的googlemapv1引起的网格线。如何将其从mapview更改为mapfragment?

public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    GoogleMap mMap;
    private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

    private Context context;

    public AddItemizedOverlay(Drawable defaultMarker) {
         super(boundCenterBottom(defaultMarker));
    }

    public AddItemizedOverlay(Drawable defaultMarker, Context context) {
         this(defaultMarker);
         this.context = context;
    }

    public boolean onTouchEvent(MotionEvent event, MapView mapView)
    {  

        if (event.getAction() == 1) {
            GeoPoint geopoint = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());
            // latitude
            double lat = geopoint.getLatitudeE6() / 1E6;
            // longitude
            double lon = geopoint.getLongitudeE6() / 1E6;
            //Toast.makeText(context, "Lat: " + lat + ", Lon: "+lon, Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    @Override
    protected OverlayItem createItem(int i) {
       return mapOverlays.get(i);
    }

    @Override
    public int size() {
       return mapOverlays.size();
    }

    @Override
    protected boolean onTap(int index) {
      OverlayItem item = mapOverlays.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(this.context);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
         }
     });
      dialog.show();
      return true;
    }

    public void addOverlay(OverlayItem overlay) {
       mapOverlays.add(overlay);
    }

    public void populateNow(){
        this.populate();
    }

 }

0 个答案:

没有答案