0

I have an ArrayList that has objects that are a latitude, and a longitude. I need to translate them to a two dimensional array.

public void DrawPolygon(ArrayList<PointModel> pModel){
    int size=pModel.size();
    double [][] latlon= new double[size][size];
    for(int i=0;i<pModel.size();i++){
        //What to do here, so I can get double[0][0][latitude of first index of arraylist][longitude of first index of array], and so on 
    }
}

Thank you!

1 Answer 1

1

You have set the wrong size for the array,it need to be double[size][2] instead of double[size][size]

public void DrawPolygon(ArrayList<PointModel> pList){
    int size=pList.size();
    double [][] latlon= new double[size][2];
    for(int i=0;i<pList.size();i++){
         latlon[i][0] = pList.get(i).getLatitude();
         latlon[i][1] = pList.get(i).getlongitude();
    }
}

Also, make an ArrayList called pModel is a very bad idea.

Sign up to request clarification or add additional context in comments.

1 Comment

Sure, I had to wait 10 minutes before I can vote, but I did not forgot about it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.