Hi all,
Good evening,
I have an application where I display overlays on a map. I have a
class that consumes a webservice that I created myself that does the
following:
- Connects to the database and returns the Latitude and Longitude of
Overlays.
So far so good, have brought the data correctly, but when I go to
create the overlays, I call the position of the list that the Overlay
is, but do not know where the food list.
See the code:
package org.ci.geo.route;
import java.util.ArrayList;
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import android.graphics.Point;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.widget.Toast;
public class HutsItemizedOverlay extends
ItemizedOverlay<OverlayItem> {
Conexao conn = new Conexao();
List<Double> lat = new ArrayList<Double>();//reported here are
the lists
List<Double> lon = new ArrayList<Double>();
public HutsItemizedOverlay(Drawable defaultMarker) {
super(defaultMarker); //If I feed this list
constructor, does not work.
boundCenterBottom(defaultMarker); //The compiler
accepts, but the application hangs
populate();
}
@Override
public GeoPoint getCenter() {
Integer averageLat = 0;
Integer averageLon = 0;
for (GeoPoint point : hutPoints) {
averageLat += point.getLatitudeE6();
averageLon += point.getLongitudeE6();
}
averageLat /= hutPoints.length;
averageLon /= hutPoints.length;
return new GeoPoint(averageLat, averageLon);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean
shadow) {
super.draw(canvas, mapView, false);
}
public GeoPoint hutPoints[] = new GeoPoint[] {
new GeoPoint((int) (lat.get(0) * 1E6), (int)
(lon.get(0) * 1E6)),//aqui eu consumo a lista, mas ela ainda não está
alimentada
//new GeoPoint(-25447305,-49307184),
};
@Override
protected OverlayItem createItem(int i) {
OverlayItem item = new OverlayItem(hutPoints[i], "Nome do
Local",
"Promocao - Detalhe");
return item;
}
@Override
public int size() {
return hutPoints.length;
}
public boolean onTap(GeoPoint geoPoint, MapView mapView) {
OverlayItem item = this.createItem(1);
Point point = mapView.getProjection().toPixels(geoPoint,
null);
RectF rectF = new RectF(point.x - 5, point.y - 5, point.x
+ 5,
point.y + 5);
boolean pontoClicado = rectF.contains(point.x, point.y);
if (pontoClicado) {
Toast.makeText(
mapView.getContext(),
"Você clicou aqui: " + item.getTitle() +
"Acesse "
+ item.getSnippet(),
Toast.LENGTH_LONG).show();
return true;
}
return super.onTap(geoPoint, mapView);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en