2017-01-10 19 views
0

ウェブサービスを使用してSQLサーバーから座標の配列を受け取るアンドロイドアプリケーションを作成しようとしています。 SQLサーバに30個の座標(緯度、経度)を含む配列があると仮定し、これらの座標をWebサービスを使用して取得し、アプリケーションで作成したマップ上にマーカーをプロットします。 助けてください。ありがとうございました!!私はあなたがさらにあなたはそれがお送りします応じてYOUR_WEB_SERVICE_URLを打ったときボレーがアンドロイドSQL Serverから座標の配列を取得し、アンドロイドのマップにプロットする

に実装されているか調べることができ呼び出しネットワークのボレーライブラリを使用しています

+0

これを見てください: [リンク](https://gist.github.com/saxman/5347195)と、この[リンク](http://stackoverflow.com/questions/13966632を/ plotting-multiple-mark-on-google-map-in-android) –

答えて

0

こんにちはホープ・U

class MyTask extends AsyncTask<Void, Void, Void> { 
    String msg = ""; 

    @Override 
    protected Void doInBackground(Void... params) { 
     // TODO Auto-generated method stub 
     try { 


      URL url = new URL(
        "url"); 

      InputStream isr = url.openStream(); 
      int i = isr.read(); 
      while (i != -1) { 
       msg = msg + (char) i; 
       i = isr.read(); 

      } 
     } catch (Exception e) { 
      // TODO: handle exception 
      e.printStackTrace(); 
     } 

     return null; 
    } 

    @Override 
    protected void onPostExecute(Void result) 

    { 
     // TODO Auto-generated method stub 
     super.onPostExecute(result); 
     Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG).show(); 
     Log.i("========>Message<=====",msg); 
     try 
     { 
      JSONObject mainObject=new JSONObject(msg); 
      //use this get Toast message of each object Toast.makeText(getActivity(), "hello1 "+mainObject, Toast.LENGTH_LONG).show(); 
      JSONObject maJsonObject = mainObject.getJSONObject("Response"); 
      //Toast.makeText(getActivity(), "hello2 "+maJsonObject, Toast.LENGTH_LONG).show(); 
      JSONArray jsonArray = maJsonObject.getJSONArray("Result"); 
      //Toast.makeText(getActivity(), "hello3 "+jsonArray, Toast.LENGTH_LONG).show(); 

       // Log.i("<======JSONARRAY==>",jsonArray.toString()); 
       for(int i=0;i<jsonArray.length();i++) 
        { 
        JSONObject subObject=jsonArray.getJSONObject(i); 
        String vocherId=subObject.getString("Voucher No"); 
        tv1.setText("Voucher ID: "+vocherId); 
        String vocherAmount=subObject.getString("Voucher Amount"); 
        tv2.setText(vocherAmount); 
        String store_name=subObject.getString("Store Name"); 
        tv3.setText(store_name); 
        String location=subObject.getString("Location"); 
        tv4.setText(location); 
        String recipient_name=subObject.getString("Recipient Name"); 
        tv5.setText(recipient_name); 
        String Recipent_mobile=subObject.getString("Recipient Mobile"); 
        tv6.setText(Recipent_mobile); 

        Toast.makeText(getActivity(), vocherId+"\n"+vocherAmount+"\n"+location+"\n", Toast.LENGTH_LONG).show(); 
        Log.i("==vocherId==", vocherId); 
        } 
       /*JSONObject jsonRootObject = new JSONObject(msg); 
       JSONArray jsonArray = jsonRootObject.optJSONArray("Response"); 
       for(int i=0; i < jsonArray.length(); i++) 
       { 
        JSONObject jsonObject = jsonArray.getJSONObject(i); 

        String VoucherId = jsonObject.optString("voucherid").toString(); 
        String Amount = jsonObject.optString("amount").toString(); 
        String StoreName = jsonObject.optString("storename").toString(); 
        String Location=jsonObject.optString("location").toString(); 
        String Recipient_Name=jsonObject.optString("recipient_name").toString(); 
        String Recepient_Mobile=jsonObject.optString("recepient_mobile").toString(); 

        msg += "Node"+i+" : \n voucerId= "+ VoucherId +" \n Amount= "+ Amount +" \n StoreName= "+ StoreName +" \n Location="+Location+"\n Recipient_Name"+Recipient_Name+"\n"+Recepient_Mobile; 

       } 
       tv1.setText(msg);*/ 
     }catch (Exception e) { 
      // TODO: handle exception 
      e.printStackTrace(); 
     } 


    } 

} 
0

にこのヘルプJSON配列を解析した後、マーカーを配置することができます

[ 
    { 
     "id": "1", 
     "lat": "21.3", 
     "lon": "23.55", 
    }, { 
     "id": "2", 
     "lat": "21.3", 
     "lon": "23.55", 
    } 
    //... 
    { 
     "id": "30", 
     "lat": "21.3", 
     "lon": "23.55" 
    } 
] 
JsonArrayRequest req = new JsonArrayRequest(YOUR_WEB_SERVICE_URL, 
      new Response.Listener<JSONArray>() { 
     @Override 

     public void onResponse(JSONArray response) { 
      Log.d(TAG, response.toString()); 
      try { 
       // Parsing json array response 
       // loop through each json object 
       jsonResponse = ""; 
       for (int i = 0; i < response.length(); i++) { 
        JSONObject location = (JSONObject)response.get(i); 
        String id = location.getString("id"); 
        String lat = location.getString("lat"); 
        String lon = location.getString("lon"); //lat and lon are String you have to typecast it to double before using it 

        Latlon ll = new Latlon(lat, lon);  
        placeYourMarkerFuction(ll);  
       } 
      } 
      catch (JSONException e) { 
       e.printStackTrace(); 
       Toast.makeText(getApplicationContext(), 
           "Error: " + e.getMessage(), 
           Toast.LENGTH_LONG).show(); 
      } 
     } 
    }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      VolleyLog.d(TAG, "Error: " + error.getMessage()); 
      Toast.makeText(getApplicationContext(), 
          error.getMessage(), Toast.LENGTH_SHORT).show(); 

     } 
    });  

    // Add Request to queue  
} 
関連する問題