2

我怎么additemizedoverlay进去mapfragment

此代码来自androidhive google places,我在使用 mapview 时遇到问题。它只显示可能由 deprecated 引起的网格线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();
    }

 }
4

0 回答 0