0

This is my code (bellow),

how to remove geopoints form code, and read it from sqlite from server? i have more than 1000 geopoints so my code is too long.

I have created datebase allready, but dont know how to connect it from server.

public class SimpleMap extends MapActivity {

    private MapView mapView;

    List<Overlay> mapOverlays;
    Drawable drawable;
    Drawable drawable2;
    MyLocationOverlay myLocationOverlay;
    SimpleItemizedOverlay itemizedOverlay2;
    SimpleItemizedOverlay itemizedOverlay;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        GeoPoint hr = new GeoPoint((int) (44.715513 * 1E6),
                (int) (16.545410 * 1E6));
        mapView.getController().animateTo(hr);
        mapView.getController().setZoom(7);

        mapOverlays = mapView.getOverlays();

        myLocationOverlay = new FixedMyLocationOverlay(this, mapView);
        mapView.getOverlays().add(myLocationOverlay);
        mapView.postInvalidate();

        drawable = getResources().getDrawable(R.drawable.icon2);
        itemizedOverlay2 = new SimpleItemizedOverlay(drawable, mapView);
        itemizedOverlay2.setShowClose(true);
        itemizedOverlay2.setShowDisclosure(false);
        itemizedOverlay2.setSnapToCenter(false);

        GeoPoint point1000 = new GeoPoint((int) (34.109798 * 1E6),
                (int) (25.242270 * 1E6));
        OverlayItem overlayItem1000 = new OverlayItem(point1000,
                "point1000", "some text");
        itemizedOverlay2.addOverlay(overlayItem1000);

        mapOverlays.add(itemizedOverlay2);
Pedantic
  • 5,032
  • 2
  • 24
  • 37
Kristijan Drača
  • 614
  • 4
  • 16
  • Can you be more specific about what you're trying to do? SQLite is designed to be used locally, not over a network connection. If you just need to download geopoints from a server, then you'll need to store them on your server in a format that your app can parse. The app can then insert them into your local database. – acj Oct 17 '12 at 15:23
  • ok, tnx for replay. I do not care which datebase will be used. I just need geopoints form server – Kristijan Drača Oct 17 '12 at 15:52

1 Answers1

1

Connecting to a remote database from a mobile device is a bad idea for a number of reasons, such as performance, security, and app extensibility. A quick search on SO will turn up many results that come to the same conclusion.

If you have control over the server, it would be best to set up a simple Web service that your app can use to retrieve geopoints. Then, rather than connecting to a database, your app would connect to a URL (e.g., using HttpUrlConnection) and download the location data. The server will need to send them in a format that is easy for your app to parse, such as a comma-separated list:

-82.8883,25.92834
2.5057,-60.90711
...

For each pair of points, create a GeoPoint, wrap it in an OverlayItem, and then add it to your Overlay.

Community
  • 1
  • 1
acj
  • 4,821
  • 4
  • 34
  • 49