-1

I know there are hundreds of questions about this, but I need to get an answer to all these questions.

Summary of my application (not my question): An application which has a map where it creates numerous markers (points of interest). When the user walks into the marker, it fires the information about that place. That information consists in the title of the place, slideshow using images from sdcard, some audio (with controls) and a small text description.


Now my big question: I need to create the best way to download all this data to my device!


I thought of downloading all the database using an XML file created by PHP.
Why I think this won't work the way I want.
I need to filter the information I want the user to download.

Well, the user just needs to Tick the information he wants to download, for example a couple of cities that have information.

For this, I thought of creating an dialog like this

Multiple select

After the user selects the cities he wants, the application must receive the information according to cities selected.

I'm here trying to find an answer for the best way of doing this.

All I have is an MySQL Database with the following structure:
id | name | radius | coords

I think by adding an column regarding the city it is associated will workout.

Regarding the information data, it will have the following folder structure:
/sdcard/{app_name}/{id_of_the_point}/{.jpg/.mp3/.txt}

For the sdcard, I compress all this information in a zip and thought of downloading it to the device and extract it somewhere in the sdcard.

Posting all the information, I need you guys to give me the best practice of doing this!

Thanks in advance!

silentw
  • 4,835
  • 4
  • 25
  • 45

2 Answers2

2

``You need to use a class extending overlay classes ,for example(do note,this code is for fetching json not xml)

public class LocationOverlay extends ItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();
Context context;

public LocationOverlay(Drawable marker, Context c) {
    super(boundCenterBottom(marker));
    // TODO Auto-generated constructor stub
    populate();
    context = c;
}

@Override
protected boolean onTap(int index) {

    Toast.makeText(context,
            "Touch on marker: \n" + overlayItemList.get(index).getTitle(),
            Toast.LENGTH_LONG).show();
    // code for passing storeid's
    OverlayItem item = overlayItemList.get(index);
    String idex = (item.getTitle());
    Intent idtent = new Intent(context, StoreDetails.class);
    idtent.putExtra("&", idex);
    context.startActivity(idtent);
    return true;

}

public void addItem(GeoPoint p, String title) {
    OverlayItem newItem = new OverlayItem(p, title, null);
    overlayItemList.add(newItem);
    populate();

}

@Override
protected OverlayItem createItem(int i) {
    // TODO Auto-generated method stub
    return overlayItemList.get(i);
}

@Override
public int size() {
    // TODO Auto-generated method stub
    return overlayItemList.size();
}

now simply in the class where you are displaying the map ,do this

Double jlat = j4.getDouble("Latitude");
                    Double jlon = j4.getDouble("Longitude");
                    Log.v("Latitude", jlat + "n");
                    Log.v("Longitude", jlon + "n");

                    // Get the distance between lat long
                    Location locationA = new Location("point A");

                    locationA.setLatitude(slat);
                    locationA.setLongitude(slon);

                    Location locationB = new Location("point B");

                    locationB.setLatitude(jlat);
                    locationB.setLongitude(jlon);

                    distance = (int) locationA.distanceTo(locationB);
                    String str = " (" + String.valueOf(distance) + " meters)";
                    Log.v("Distance", str);

                    // adjust drawable params
                    Drawable marker = getResources().getDrawable(
                            android.R.drawable.star_big_on);
                    Drawable user = getResources().getDrawable(
                            android.R.drawable.arrow_down_float);
                    int userWidth = user.getIntrinsicWidth();
                    int userHeight = user.getIntrinsicHeight();
                    user.setBounds(0, userHeight, userWidth, 0);
                    int markerWidth = marker.getIntrinsicWidth();
                    int markerHeight = marker.getIntrinsicHeight();
                    marker.setBounds(0, markerHeight, markerWidth, 0);

                    // refernc to overlay class
                    LocationOverlay myItemizedOverlay = new LocationOverlay(
                            marker, MapActivity.this);
                    LocationOverlay myItemizedOverlay1 = new LocationOverlay(
                            user, MapActivity.this);
                    mapView.getOverlays().add(myItemizedOverlay);
                    mapView.getOverlays().add(myItemizedOverlay1);

                    // create geopoint for user
                    GeoPoint usr = new GeoPoint((int) (slat * 1e6),
                            (int) (slon * 1e6));
                    // add overlay(user) to user's location
                    myItemizedOverlay1.addItem(usr, "User");
                    mc.animateTo(usr);

and in the class above you can add any sort of handler whenever the user taps a geopoint..

Aalok Sharma
  • 1,025
  • 2
  • 12
  • 26
  • Thanks for trying to help, but all that stuff is already coded by me and it's working great. I'm in need of creating an activity to download all the data, before it shows the map with all the data :) – silentw May 31 '12 at 11:55
  • What are you parsing xml or json ? – Aalok Sharma May 31 '12 at 11:57
  • I thought of creating an xml. But I'm trying to find out which is the better way of doing this :) – silentw May 31 '12 at 11:58
  • 1
    Json is supposed to be a fat free version of xml ,if you need the code for parsing json from webservice than I suggest you try this http://www.androidhive.info/2012/01/android-json-parsing-tutorial/ From the response that you get from the server, You can parse out the relevant items that you need and for xml try this http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/ – Aalok Sharma May 31 '12 at 12:00
-1

I haven't worked on this project till now.

So after all the research, I found the best way to do this.

I used JSON :)

Firstly, populate the multi-select dialog using json data (working on it)
Secondly, after selecting, using json, fetch all the data associated to the selected city.



And my problem is now gone! :)

silentw
  • 4,835
  • 4
  • 25
  • 45