Question

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);
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top