1
19sheriff93
Neues Mitglied
- 0
Hi leute!
habe vor einigen Monaten meine erste App geschrieben, hab ich dann auch in den play store hochgeladen und alles hat funktioniert. Jetzt bin ich momentan dabei eine ähnliche app zu schreiben, habe aber mit Google maps probleme :S
Folgendes Problem:
Alle Informationen werden aus einer Datenbank bezogen, die Regionen der unterschiedlichen Standorte sind von 1-9 unterteilt. Nun werden nur mehr 2 Regionen angezeigt, sowie keine karte.. kann mir bitte jemand weiterhelfen?
Code MapActivity:
habe vor einigen Monaten meine erste App geschrieben, hab ich dann auch in den play store hochgeladen und alles hat funktioniert. Jetzt bin ich momentan dabei eine ähnliche app zu schreiben, habe aber mit Google maps probleme :S
Folgendes Problem:
Alle Informationen werden aus einer Datenbank bezogen, die Regionen der unterschiedlichen Standorte sind von 1-9 unterteilt. Nun werden nur mehr 2 Regionen angezeigt, sowie keine karte.. kann mir bitte jemand weiterhelfen?
Code MapActivity:
Code:
package at.android.twhk;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
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.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class LocationDemo2 extends MapActivity {
private static final String TAG = "**** "+LocationDemo2.class.getSimpleName();
private MapController mapController;
MapView mapView;
GeoPoint geoPoint;
boolean art;
int pFeld[];
int districtID;
double zielLat,zielLng; //geographische Breite,Länge als Parameter des Ziels
private boolean DEBUG = false;
//Buttons:
public void StartseiteKlick (View vies) {
setContentView(R.layout.startseite);
}
public void GooglemapsKlick (View vies) {
setContentView(R.layout.googlemaps);
}
public void SucheKlick (View vies) {
setContentView(R.layout.suche);
}
public void BezirkeKlick (View vies) {
setContentView(R.layout.bezirke);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent in = getIntent();
art = in.getBooleanExtra("karte", false);
if (art) { //Karte mit allen Betrieben des Bezirks
districtID=in.getIntExtra("districtID",0);
pFeld = in.getIntArrayExtra("pFeld"); //Koordinaten der Betriebe
} else { //Karte mit dem aus der Liste gewählten Betrieb im Mittelpunkt
zielLat = in.getFloatExtra("lat",0);
zielLng = in.getFloatExtra("lng",0);
geoPoint = new GeoPoint((int)(zielLat*1E6), (int)(zielLng*1E6));
}
// Zoom aktivieren
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
// MapController ermitteln
mapController = mapView.getController();
} //Ende onCreate
@Override
protected void onStart() {
super.onStart();
if (!art) { //Karte nur für aus der Liste ausgewählten Betrieb
//fügt der MapView neues Overlay (zum zeichnen der 'current location') hinzu
List<Overlay> overlays = mapView.getOverlays();
// overlays.clear();
overlays.add(new MyOverlay());
} else //alle Betriebe in Karte zeichnen
multipleItems();
}
private void multipleItems() {
// mapView.setSatellite(true);
Drawable markerDefault = this.getResources().getDrawable(R.drawable.mm_20_green);
MyItemizedOverlay itemizedOverlay = new MyItemizedOverlay(markerDefault);
//für alle Betriebe ein Item aus den Koordinaten bilden und die
//where-Klausel mit der _id des Betriebes hinzufügen für onTap
for (int i=0; i<pFeld.length; i+=3) {
if (pFeld[i+1] > 0)
itemizedOverlay.addOverlayItem(pFeld[i+1],pFeld[i+2],"_id="+pFeld[i]);
}
//alle Items zur MapView hinzufügen
mapView.getOverlays().add(itemizedOverlay);
//den Mittelpunkt für den ausgewählten District heraussuchen
int lat=0,lng=0;
for (int i=0; i < Notepadv1.mpFeld.length; i+=3) {
if (Notepadv1.mpFeld[i] == districtID) {
lat = Notepadv1.mpFeld[i+1];
lng = Notepadv1.mpFeld[i+2];
//Darstellung Mittelpunkt
// itemizedOverlay.addOverlayItem(lat,lng,"",this.getResources().getDrawable(R.drawable.marker_default));
mapController.setCenter(new GeoPoint(lat,lng));
break;
}
}
if (DEBUG) {
String message="Anzahl Koord.:"+pFeld.length/3+", Mitte:"+lat+","+lng;
Log.i(TAG,message);
Toast.makeText(LocationDemo2.this, message, Toast.LENGTH_LONG).show();
}
mapController.zoomToSpan(itemizedOverlay.getLatSpanE6(), itemizedOverlay.getLonSpanE6());
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
/* a private inner class which extends Overlay and override the draw method
* http://androidcookbook.com/Recipe.seam?recipeId=1541
* zeichnet als 'overlay' den 'geoPoint' in die Karte
*/
private class MyOverlay extends com.google.android.maps.Overlay {
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
if (!shadow && geoPoint != null) {
mapController.setCenter(geoPoint);
Point point = new Point(); //wird Koordinate des GeoPoint
mapView.getProjection().toPixels(geoPoint, point);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),//R.drawable.marker_default);
R.drawable.mm_20_green);
// Shift it left so the center of the image is aligned with the x-coordinate of the geo point
int x = point.x - bmp.getWidth() / 2;
// Shift it upward so the bottom of the image is aligned with the y-coordinate of the geo point
int y = point.y - bmp.getHeight();
canvas.drawBitmap(bmp, x, y, null);
}
}
}
private class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private List<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public void addOverlayItem(int lat, int lon, String title, Drawable altMarker) {
GeoPoint point = new GeoPoint(lat, lon);
OverlayItem overlayItem = new OverlayItem(point, title, null);
addOverlayItem(overlayItem, altMarker);
}
public void addOverlayItem(int lat, int lon, String title) {
GeoPoint point = new GeoPoint(lat, lon);
OverlayItem overlayItem = new OverlayItem(point, title, null);
addOverlayItem(overlayItem);
}
public void addOverlayItem(OverlayItem overlayItem) {
mOverlays.add(overlayItem);
populate();
}
public void addOverlayItem(OverlayItem overlayItem, Drawable altMarker) {
overlayItem.setMarker(boundCenterBottom(altMarker));
addOverlayItem(overlayItem);
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
protected boolean onTap(int index) {
if (DEBUG)
Toast.makeText(LocationDemo2.this,
getItem(index).getTitle()+", Index:"+index, Toast.LENGTH_LONG).show();
Intent in = new Intent(getApplicationContext(),Notepadv1.class);
in.putExtra("art", "where");
//_id des gewählten Listenpunktes
in.putExtra("where", getItem(index).getTitle());
//Info-Daten zum gewählten Betrieb anzeigen
String infotext = new hashmap().texte.get(index + 1);
new AlertDialogManager().showAlertDialog(LocationDemo2.this, "info", infotext, in);
return true;
}
public class AlertDialogManager
{
public void showAlertDialog(Context context, String title, String infoText, final Intent in)
{
final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(infoText);
alertDialog.setButton("Info", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
startActivity(in);
}
});
alertDialog.setButton2("zurück", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
alertDialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
}
}
public void finish() {}
public void finishAffinity() {}
}