简体   繁体   中英

Get latitude and longitude from json file and insert points to google map - Android

{"data":{"columns":["location_id","name","description","latitude","longitude","error","type","type_id","icon_media_id","item_qty","hidden","force_view","allow_quick_travel"],"rows":[[2,"Editor","",43.076014654537,-89.399642451567,25,"Npc",1,0,1,"0","0","0"],[3,"Dow Recruiter","",43.07550842555,-89.399381822662,25,"Npc",2,0,1,"0","0","0"],[4,"Protestor","",43.074933,-89.400438,25,"Npc",3,0,1,"0","0","0"],[5,"State Legislator","",43.074868061524,-89.402136196317,25,"Npc",4,0,1,"0","0","0"]]},"returnCode":0,"returnCodeDescription":null}

I have this JSON string in file. I'm using function to connect to json file, this is my parsing where i'm getting latitude and logitude. What should i do next?

JSONObject data = new JSONObject(convertStreamToString(jsonString)).getJSONObject("data");
                // Get the query value'

                JSONArray Acolumns = data.getJSONArray("columns");
                JSONArray Arows = data.getJSONArray("rows");



                for (int i = 0; i < Arows.length(); i++) {
                    JSONArray rec = Arows.getJSONArray(i);
                    //stringJsonResult += "\n rows:" + rec;
                    int latitude = rec.getInt(3);
                    int longitude = rec.getInt(4);

                    //stringJsonResult += "\n  latitude + longitude;
                }

                jsonString.close();
                //JsonResult.setText("\n" + stringJsonResult);

Thanks for help, Michal.

EDIT:: Ok thank you ryanm for help, your app works ;) Is it possible to make JSON array with latitude and longitude for example: {points: {[lat1, long1],[lat2,long2]} and add it to google map? Have somebody diffrent idea to solve my problem?

Check out this app for pointers. It downloads a json string, parses it, and displays lat/lon points on a map view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM