2012-06-20 38 views
0

我在Google地圖視圖上繪製了覆蓋圖(封閉多邊形,已填充)。但是現在我不知道如何在點擊覆蓋層時彈出烤麪包。大多數例子,我發現與標記工作,看起來嚴重不同,我的代碼。如何在OnTouch的油漆覆蓋(谷歌地圖)?

主要活動:

public class BOSLstItemDetail extends MapActivity{ 
    ArrayList<HashMap<String, Object>> boslst; 
    MapView mapView; 
    MapController mapcontrol; 
    GeoPoint p; 
    Polygon polygon; 

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

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.boslst_item_detail); 



     String coordinates[] = {"48.098056", "9.788611"}; 
     double lat = Double.parseDouble(coordinates[0]); 
     double lng = Double.parseDouble(coordinates[1]); 

     p = new GeoPoint(
       (int) (lat * 1E6), 
       (int) (lng * 1E6)); 

     MapView mapView = (MapView) findViewById(R.id.mapview); 
     mapcontrol = mapView.getController(); 
     mapcontrol.animateTo(p); 
     mapcontrol.setZoom(10); 
     mapView.setBuiltInZoomControls(true); 

     ArrayList<GeoPoint> points = new ArrayList<GeoPoint>(); 
     try{ 
      InputStream koord = getAssets().open("gps.txt"); 
      if (koord != null) { 
       InputStreamReader input = new InputStreamReader(koord); 
       BufferedReader buffreader = new BufferedReader(input); 
       String line; 
       while ((line = buffreader.readLine()) != null) { 
        String[] point_t = line.split(","); 
         double y = Double.parseDouble(point_t[0]); 
         double x = Double.parseDouble(point_t[1]); 
         points.add(new GeoPoint((int)(x*1e6), (int)(y*1e6))); 
       } 
       koord.close(); 
       polygon = new Polygon(points); 
      } 
     }catch (Exception e) { 
      Log.e("APP","Failed", e); 
     }   

     mapView.getOverlays().clear(); 
     mapView.getOverlays().add(polygon); 
     mapView.invalidate(); 
    } 
} 

Polygon.java

public class Polygon extends Overlay { 
    ArrayList<GeoPoint> geoPoints; 

    public Polygon(ArrayList<GeoPoint> points){ 
     geoPoints = points; 
    } 

    @Override 
    public void draw(Canvas canvas, MapView mapView, boolean shadow){ 
     //Set the color and style 
     Paint paint = new Paint(); 
     paint.setColor(Color.parseColor("#88ff0000")); 
     paint.setAlpha(50); 
     paint.setStyle(Paint.Style.FILL_AND_STROKE); 

     //Create path and add points 
     Path path = new Path(); 
     Point firstPoint = new Point(); 
     mapView.getProjection().toPixels(geoPoints.get(0), firstPoint); 
     path.moveTo(firstPoint.x, firstPoint.y); 

     for(int i = 1; i < geoPoints.size(); ++i){ 
      Point nextPoint = new Point(); 
      mapView.getProjection().toPixels(geoPoints.get(i), nextPoint); 
      path.lineTo(nextPoint.x, nextPoint.y); 
     } 

     //Close polygon 
     path.lineTo(firstPoint.x, firstPoint.y); 
     path.setLastPoint(firstPoint.x, firstPoint.y); 
     canvas.drawPath(path, paint); 
     super.draw(canvas, mapView, shadow); 

    } 
} 

gps.txt:

9.34669876098644,48.2405319213867 
9.36384963989269,48.2296714782715 
9.3639497756958,48.2259712219238 
9.87827968597418,48.2786293029785 
9.87261867523205,48.2822494506837 
9.87254810333263,48.2859611511232 
9.88368034362787,48.2898597717285 
9.8835382461549,48.2972793579102 
9.72781181335461,47.9827613830566 
9.72225093841558,47.9826812744141 
9.72232818603527,47.9789619445801 
9.71129894256597,47.9750900268555 
9.70574092864985,47.9750099182129 
9.70557022094732,47.9824409484864 
9.69992923736572,47.9860801696778 
9.69436073303234,47.9860000610352 
9.33546066284174,48.2403602600099 
9.34669876098644,48.2405319213867 

回答

0

如果你正在擴大覆蓋,可以覆蓋和Ontap方法:

protected boolean onTap(final int index) 
{ 
    OverlayItem item = mOverlays.get(index); 
    if(item != null){ 
     Toast.makeText(mContext, textToShow, Toast.LENGTH_SHORT).show(); 
    }  
    //return true to indicate we've taken care of it 
    return true; 
} 
+0

延期是什麼意思? – Laire

+0

「公共課多邊形延伸覆蓋」你擴展類「覆蓋」 – Guardanis

+0

但我必須添加onTapp和我有什麼編輯?示例你發佈的地圖是什麼OverlayItems像marker或? – Laire