-1

I'm gonna be doing android app like as show multi-location on google map v2 that point are already stored in sqlte database. But now, I'm facing some problems that doesn't show any location. also don't get any error. What's the wrong it?

My code

Map Activity class

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.example.location_application_v1.R;
import com.google.android.gms.internal.gs;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class AllMap extends Activity {
    ArrayList<GS> q = new ArrayList<GS>();
    private GoogleMap googleMap;
    String name;
    double lat;
    double lang;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_map);
        try {
            initilizeMap();
        } catch (Exception e) {
            e.printStackTrace();
        }
        DBAdapter db = DBAdapter.getDBAdapter(getApplicationContext());
        db.openDatabase();
        db.GetAllPin();
        for (int i = 0; i < q.size(); i++) {
            Log.i("arr", "" + q.get(i).getId());
            // lat=db.GetAllPin().get(i).getLat();
            // lang=db.GetAllPin().get(i).getLng();
            lat = q.get(i).getLat();
            lang = q.get(i).getLng();

            LatLng latlng = new LatLng(lat, lang);
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map1)).getMap();
            googleMap.addMarker(new MarkerOptions().position(
                    new LatLng(lat, lang)).title(q.get(i).getName()));

        }

    }

    private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map1)).getMap();
            googleMap.addMarker(new MarkerOptions().position(new LatLng(lat,
                    lang)));

            // check if map is created successfully or not
            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();

            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }

}

1 Answers1

0

I think you need change:

db.GetAllPin();

to

 q = db.GetAllPin();

you have initialized q but you don't set anything to that, as GetAllPin returns ArrayList<GS> I think you forgot set that to q as on next line you have trying go trough q with following code:

for (int i = 0; i < q.size(); i++)
Shayan Pourvatan
  • 11,898
  • 4
  • 42
  • 63