2014-04-03 93 views
0

我想知道如何在Android中的Google Map中添加多個標記。我設置的座標是存儲在在線數據庫中,然後編碼爲JSON。然後通過JSON解析器類分析這些JSON座標以檢索信息並存儲在arrya中。然而,我似乎無法弄清楚如何遍歷存儲座標的JSON數組,以將它們添加爲谷歌地圖的標記。使用JSON將多個標記添加到Android Google地圖。

+0

這裏發表您的JSON數組 –

回答

2

試試這個

if (result != null) { 

       try { 
        JSONArray jArray = new JSONArray(result); 
        Log.i("JSON ARRAY","" + jArray); 

        for(int i=0;i<jArray.length();i++){ 



         JSONObject tableData = jArray.getJSONObject(i); 

         lot_id = tableData.getString("id"); 


         lot_number = tableData.getString("lot_number"); 


         coordinate_late = tableData.getString("coordinate_late"); 


         coordinate_long = tableData.getString("coordinate_long"); 


          latitude_lot_numer = Double.parseDouble(coordinate_late); 
          longitude_lot_number = Double.parseDouble(coordinate_long); 
          // create marker 
           MarkerOptions client_marker = new MarkerOptions().position(new LatLng(latitude_lot_numer, longitude_lot_number)); 
           client_marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)); 
           // adding marker 
           mMap.addMarker(client_marker); 

         arraylist_of_lot_number.add(lot_number); 
         Log.i("ArrayList Async in loop",""+ arraylist_of_lot_number); 
         lot_id_arraylist.add(lot_id); 


         if(arraylist_of_lot_number.isEmpty()){ 
          Toast.makeText(getApplicationContext(), "Empty List for Unpaid Lot", Toast.LENGTH_LONG).show(); 
         } 

} catch (JSONException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 


      } 
0

一個addMaker

for (int i = 0; i < jsonarray.length(); i++) { 
    JSONObject j = jsonarray.optJSONObject(i); 

    MarkerOptions m = new MarkerOptions() 
     .title(j.optString("title")) 
     .position(new LatLng(j.optDouble("lat"), j.optDouble("lng"))) 

    gmap.addMarker(m); 

} 
相關問題