Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6117775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:21:33+00:00 2026-05-23T15:21:33+00:00

I need to get latitude and longitude to my android, it got many values

  • 0

I need to get latitude and longitude to my android, it got many values like this :
enter image description here

I tried this to get values from JSON :

ArrayList<String> longitude;
ArrayList<String> latitude;

public void parseJson(String result) {
        try {
            JSONArray jArray = new JSONArray(result);
            for (int i = 0; i < jArray.length(); i++) {
                JSONObject jo = jArray.getJSONObject(i);
                latitude.add(jo.getString("Latitude").toString());
                longitude.add(jo.getString("Longitude").toString());
            }
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());
        }
    }

But When I check the size of array, it’s empty.
Anyone can help or suggest my wrong ? Thanks

@after modified,I still got 0 size of array. So,I tried to search where it’s stop by Toast then I found :

public void parseJson(String result) throws JSONException {

        longitude = new ArrayList<String>();
        latitude = new ArrayList<String>();

        JSONArray jArray = (JSONArray)JSONValue.parse(result);

        for (Object obj: jArray) {

            JSONObject jo = (JSONObject)obj;
            //here is when I toast it's got nothing
            latitude.add(jo.get("Latitude").toString());
            longitude.add(jo.get("Longitude").toString());
        }

    }

@aroth I got an answer!! I back to use my way like this :

public void parseJson(String result) throws JSONException {

        longitude = new ArrayList<String>();
        latitude = new ArrayList<String>();
        JSONArray jArray = new JSONArray(result);
        for (int i = 0; i < jArray.length(); i++) {
            JSONObject jo = jArray.getJSONObject(i);
            latitude.add(jo.getString("Latitude").toString());
            longitude.add(jo.getString("Longitude").toString());
        }

I think I forgot declare these:

         longitude = new ArrayList<String>();
         latitude = new ArrayList<String>();

I still no idea why your code is not work. However, thank a lot for your help :))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:21:34+00:00Added an answer on May 23, 2026 at 3:21 pm

    The json.org library is needlessly obtuse with its get<Type> methods that all pointlessly throw JSONException, I would recommend switching to simple-json. Then you could do:

    ArrayList<String> longitude;
    ArrayList<String> latitude;
    
    public void parseJson(String result) {
        longitude = new ArrayList<String>();
        latitude = new ArrayList<String>();
        JSONArray jArray = (JSONArray)JSONValue.parse(result);
        for (Object obj : jArray) {
            JSONObject jo = (JSONObject)obj;
            latitude.add(jo.get("Latitude").toString());
            longitude.add(jo.get("Longitude").toString());
        }
    
    }
    
    //a simple test case
    public static void main(String[] args) {
        String json = "[{\"Latitude\": \"1.23\", \"Longitude\": \"1.23\"}, \n{\"Latitude\": \"1.23\", \"Longitude\": \"1.23\"}, \n{\"Latitude\": \"1.23\", \"Longitude\": \"1.23\"}]";    
        MyParser parser = new MyParser();
        parser.parseJson(json);
    
        //should print:  3, 3
        System.out.println(parser.latitude.size() + ", " + parser.longitude.size());
    }
    

    Should work, assuming your input JSON matches your example snippet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to draw a Polygon from several points (I have their latitude, longitude).
Possible Duplicate: How to get Latitude and Longitude of the mobiledevice in android? I
I'm working with SimpleGeo API and I need to get place's latitude/longitude by ZIP
how to get latitude and longitude values of a particular place using objective-c ?
Possible Duplicate: How Do I Get The Correct Latitude and Longitude From An Uploaded
few month ago i write something to get the latitude or longitude from google
I need help with parsing json string in Java Android Appl. Text of JSON
I need some help to get the Latitude and Longitude dynamically of a ZIP
i need to get latitude and longitude using gps on blackberry. When i check
i need to get (somehow) the longitude/latitude of a user once they click on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.