0

Google Maps Android API v2を使用してマップ上に複数のピンを取得しようとして います SQlite DB から緯度/経度の値を取得しました マップにピンを追加するときにスタックします (解析エラーの取得 - この 51.4738 文字列を解析できません) Int に)

私のコードは次のようなものです:

public class MainActivity extends FragmentActivity {
 static final LatLng HAMBURG = new LatLng(53.558, 9.927);
private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     DataBaseHelper myDbHelper = new DataBaseHelper(this);
        myDbHelper = new DataBaseHelper(this);

        try {

            myDbHelper.createDataBase();

    } catch (IOException ioe) {

        throw new Error("Unable to create database");

    }

    try {

        myDbHelper.openDataBase();


        Cursor cursor = myDbHelper.getAllContacts();

            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();     

                int nameIndex = cursor.getColumnIndexOrThrow("name");
            int latIndex = cursor.getColumnIndexOrThrow("latitude");
            int lngIndex = cursor.getColumnIndexOrThrow("longitude");
                String[] result_lats = new String [cursor.getCount()];
                String[] result_lngs = new String [cursor.getCount()];
                String[] result_names = new String [cursor.getCount()];
                 while(cursor.moveToNext()){


                 String lats = cursor.getString(latIndex);
                 String lngs = cursor.getString(lngIndex);
                 String nme = cursor.getString(nameIndex);

              //     Double lat = cursor.getFloat(latIndex) * 1E6;
              //    Double lnt = cursor.getFloat(lngIndex) * 1E6;

                 result_lats [cursor.getPosition()] = String.valueOf(lats);

            // tried this also :
    //       result_lats [cursor.getPosition()] = String.valueOf(lat); 
    //   use lat.intValue() when adding on marker 
// -- Output(Using String.valueOf(lat.intValue()))- 10 Greek Street 51514098/-130659    
// -- Output(Using String.valueOf(lat)) - 10 Greek Street 5.1514098E7/-130659.0
                 result_lngs [cursor.getPosition()] = String.valueOf(lngs);
                 result_names [cursor.getPosition()] = nme;

                 }

                 Log.d("Latitude22 :", String.valueOf(result_lats[2])); // `Output Lat -> 51.5195`
                     Log.d("Longitude22", String.valueOf(result_lngs[2]));
Output Long -> -0.126092

     // Integer Longitu = Integer.valueOf(lats[1]);

     // Integer Latitu = Integer.valueOf(result_lngs[1]);

      mMap.addMarker(new MarkerOptions().position(new LatLng(51.156685, -0.165324)).title(result_names[1]));


      for(int i=0 ; i<result_lats.length ; i++){
          Log.d("Names are :", String.valueOf(result_names[i]));
          Log.d("Latitudes are :", String.valueOf(result_lats[i])); 
          Log.d("Longitudes are :", String.valueOf(result_lngs[i]));

What should my code be to be used here so that i can get all pins shown on Map 
i knw it will be somewhat like this :

// mMap.addMarker(new MarkerOptions().position(new LatLng(result_lats[i], result_lngs[i]).title(result_names[i]));

// but the format is likely this : LatLng(53.558, 9.927); and here i have String value result_lats[i]

      }


     cursor.close();
  // ---- End Cursor coding 
    }catch(SQLException sqle){

        throw sqle;

    }
}

誰でもこれで私を助けてください...

今は解決しました。次のようにするだけです。

for(int i=0 ; i<result_lats.length ; i++){
          Log.d("Names are :", String.valueOf(result_names[i]));
          Log.d("Latitudes are :", String.valueOf(result_lats[i])); 
          Log.d("Longitudes are :", String.valueOf(result_lngs[i]));

          Double lat2 = Double.valueOf(result_lats[i]);
             Double lng2 = Double.valueOf(result_lngs[i]);
             mMap.addMarker(new MarkerOptions().position(new LatLng(lat2,lng2)).title(result_names[i]));


      }
4

1 に答える 1