Selaa lähdekoodia

Functioning places display

master
Chris Smith 14 vuotta sitten
vanhempi
commit
83eeab187c

BIN
code/PlacesDisplay/dist/PlacesDisplay.apk Näytä tiedosto


+ 1
- 0
code/PlacesDisplay/src/uk/co/md87/android/common Näytä tiedosto

@@ -0,0 +1 @@
1
+../../../../../../Common/

+ 20
- 3
code/PlacesDisplay/src/uk/co/md87/android/placesdisplay/PlacesDisplay.java Näytä tiedosto

@@ -22,6 +22,9 @@
22 22
 
23 23
 package uk.co.md87.android.placesdisplay;
24 24
 
25
+import android.content.ContentResolver;
26
+import android.database.Cursor;
27
+import android.net.Uri;
25 28
 import android.os.Bundle;
26 29
 import com.google.android.maps.GeoPoint;
27 30
 import com.google.android.maps.MapActivity;
@@ -29,6 +32,7 @@ import com.google.android.maps.MapView;
29 32
 import com.google.android.maps.Overlay;
30 33
 import com.google.android.maps.OverlayItem;
31 34
 import java.util.List;
35
+import uk.co.md87.android.common.model.Place;
32 36
 
33 37
 /**
34 38
  * Activity which displays all known places on a map.
@@ -51,11 +55,24 @@ public class PlacesDisplay extends MapActivity {
51 55
                 .getDrawable(R.drawable.icon));
52 56
         List<Overlay> mapOverlays = mapView.getOverlays();
53 57
 
54
-        GeoPoint point = new GeoPoint(19240000,-99120000);
55
-        OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
58
+        final Cursor cursor = managedQuery(Place.CONTENT_URI,
59
+                new String[] { Place.LATITUDE, Place.LONGITUDE },
60
+                null, null, null);
56 61
 
57
-        overlay.addOverlay(overlayitem);
62
+        if (cursor.moveToFirst()) {
63
+            final int latitudeColumn = cursor.getColumnIndex(Place.LATITUDE);
64
+            final int longitudeColumn = cursor.getColumnIndex(Place.LONGITUDE);
65
+            do {
66
+                final double latitude = cursor.getDouble(latitudeColumn);
67
+                final double longitude = cursor.getDouble(longitudeColumn);
58 68
 
69
+                GeoPoint point = new GeoPoint((int) (latitude * 1000000),
70
+                        (int) (longitude * 1000000));
71
+                OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
72
+
73
+                overlay.addOverlay(overlayitem);
74
+            } while (cursor.moveToNext());
75
+        }
59 76
         mapOverlays.add(overlay);
60 77
     }
61 78
 

Loading…
Peruuta
Tallenna