views:

33

answers:

0

Hi hi,

I've got a script which gets data from a MySQL database through an http request, puts it into a json array, then puts each item into an itemized overlay array so that each item can be put onto a map.

Problem is, it takes > 5 minutes to load all the items into the itemized overlay, and is then dog-slow at actually running. It starts by adding then quickly, then slows down to around 5-10 seconds per item later on.

So, my question is this: how can I speed it up? Do I need to free up each overlay item after I use it (if so how), or would it be faster to put everything into a local SQLite database and use that instead?

Cheers in advance!

MySQLConnect mysql = new MySQLConnect();        
JSONObject jObjSite = new JSONObject();        
JSONArray jArray = mysql.parseJson(); 

// create overlays array
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable marker = this.getResources().getDrawable(R.drawable.icon);
PzlItemizedOverlay itemizedoverlay = new PzlItemizedOverlay(marker, this);

try {           

    for(int i=0;i<jArray.length();i++){
        try {
        jObjSite = jArray.getJSONObject(i);

    //parse address
    String strAddress = jObjSite.getString("address");;
    Integer intLat = jObjSite.getInt("lat");
    Integer intLng = jObjSite.getInt("lng");

    if (strAddress.length() > 1 ) {
        String strName = jObjSite.getString("name");
        Log.i("Site.added",strName);
        GeoPoint point = new GeoPoint(intLat,intLng);
        OverlayItem overlayitem = new OverlayItem(point, strName, jObjSite.getString("phone"));         
        itemizedoverlay.addOverlay(overlayitem);
    }
    } catch (JSONException e) {
        e.printStackTrace();        
    } catch (Exception e){
    e. printStackTrace();
    }
    };

} catch (IllegalArgumentException e) {
e.printStackTrace();            
}

// add overlay to map
mapOverlays.add(itemizedoverlay);