簡體   English   中英

從json文件獲取經度和緯度並將點插入到Google Map-Android

[英]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}

我的文件中有這個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]}並將其添加到Google地圖? 有別人不同意解決我的問題嗎?

簽出這個程序的指針。 它下載一個json字符串,進行解析,並在地圖視圖上顯示經緯度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM