从json文件获取经度和经度,并将点插入谷歌地图 - Android

时间:2011-07-29 08:53:21

标签: java android json google-maps

{"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}

我在文件中有这个JSON字符串。我正在使用函数连接到json文件,这是我的解析,我正在获得纬度和逻辑。我接下来该怎么做?

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);

感谢您的帮助,Michal。

编辑::好的,谢谢你ryanm的帮助,你的应用程序工作;)是否可以制作具有纬度和经度的JSON数组,例如:{points:{[lat1,long1],[lat2,long2]}并添加它到谷歌地图?有什么不同的想法来解决我的问题?

1 个答案:

答案 0 :(得分:0)

查看this app以获取指针。它下载一个json字符串,解析它,并在地图视图上显示lat / lon点。