0
新手,我有類:類在for循環中
類PolyOverlay擴展覆蓋{
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
try {
List<GeoPoint> points = new ArrayList<GeoPoint>();
GeoPoint tmpPoint;
double lat2;
double lng2;
String args[] = {"",""};
args = sitesList.getpolyLine().get(daI).split("\\;");
//Toast.makeText(getApplicationContext(),"T: " + args[0],Toast.LENGTH_SHORT).show();
for (int i = 0; i < args.length; i++) {
String coordinates2[] = {"",""};
String args2[] = {"",""};
args2 = args[i].split("\\,");
coordinates2[0]= args2[0];
coordinates2[1]= args2[1];
//Toast.makeText(getApplicationContext(),"T: " + coordinates2[0],Toast.LENGTH_SHORT).show();
lat2= Double.parseDouble(coordinates2[0]);
lng2= Double.parseDouble(coordinates2[1]);
tmpPoint = new GeoPoint((int) (lat2 * 1E6), (int) (lng2 * 1E6));
points.add(tmpPoint);
}
//for(Polygon polygonTemp : polygonList)
//{
Path p = new Path();
Projection projection = mapView.getProjection();
boolean firstTime = true;
for(GeoPoint geoPoint : points)
{
Point drawPoint = new Point();
projection.toPixels(geoPoint, drawPoint);
if(firstTime)
{
p.moveTo(drawPoint.x, drawPoint.y);
firstTime = false;
}
else
{
p.lineTo(drawPoint.x, drawPoint.y);
}
}
p.setFillType(Path.FillType.EVEN_ODD);
Paint polyPaint = new Paint();
polyPaint.setStrokeWidth(1);
polyPaint.setStyle(Paint.Style.FILL_AND_STROKE);
polyPaint.setAntiAlias(true);
polyPaint.setColor(Color.BLUE);
polyPaint.setAlpha(30);
canvas.drawPath(p, polyPaint);
firstTime = true;
//}
super.draw(canvas, mapView, shadow);
} catch (Exception e) {
Toast.makeText(epapp.this, "Err: " + e, Toast.LENGTH_LONG).show();
}
}
}
然後一個XML環路我做這裏面:
for (int i = 0; i < sitesList.getStrap().size(); i++) {
//icons
String pargs[] = sitesList.getCentr().get(i).split("\\,");
String coordinates3[] = {"",""};
coordinates3[0] = pargs[0].toString();
coordinates3[1] = pargs[1].toString();
//Toast.makeText(epapp.this, "Center: " + coordinates3[0], Toast.LENGTH_LONG).show();
double lat2 = Double.parseDouble(coordinates3[0]);
double lng2 = Double.parseDouble(coordinates3[1]);
np = new GeoPoint(
(int) (lat2 * 1E6),
(int) (lng2 * 1E6));
Drawable drawable = this.getResources().getDrawable(R.drawable.iconresidential);
IconItemizedOverlay itemizedoverlay = new IconItemizedOverlay(drawable,this);
OverlayItem overlayitem = new OverlayItem(np, "Property Information", "JONES EMERSON ROBERT JR & SARA MARIA<br>1032 Briarwood Dr Wauchula 33873<br>HARDEE County<br>STRAP 05-34-25-0865-00001-0020");
itemizedoverlay.addOverlay(overlayitem);
mapView.getOverlays().add(itemizedoverlay);
//if (i==1){
//polyString = sitesList.getpolyLine().get(i);
daI=i;
//polygon
PolyOverlay myPolyOverlay = new PolyOverlay();
mapView.getOverlays().add(myPolyOverlay);
//}
}
確定,因此「問題「是如果我做// if(i == 1){在」daI「被設置爲」i「的循環中的一部分,我的」Polygon「顯示在XML中該項目的地圖上,if我「REM」出來,多邊形覆蓋圖總是XML中的最後一項。 xml列表總是有20個項目,並且好像「daI」變量始終爲19(最後一個索引在列表0-19中)
顯然不會做某些事情,所以PolyOverlay類會「完成」在xml循環完成之前?它類似於XML循環蠅通過套「戴」到最後一個和PolyOverlay被載入該最後一個項目的多邊形...
我的圖標就好了BTW在地圖上...
+1爲承認你被推遲了。 – 2011-03-23 02:42:21