0

jsonからLat-Lonが必要なため、postexecuteメソッドでマップ上に複数のマーカーを更新しました。 4-5秒間ハングアップを取得し、いつかメッセージにJSONからの応答を取得した後に複数のマーカーを追加すると、アプリケーションがメインスレッドで多すぎる作業をしている可能性があります。

を応答していない

アプリケーションを示し、ここに私のコード - ある

try{ 
     JSONArray jsonArray = jsonObject.getJSONArray("data"); 
     for (int i = 0; i < jsonArray.length(); i++) { 

      jsonObject2=jsonArray.getJSONObject(i); 
      ViewAgency_Set_Get set_Get = new ViewAgency_Set_Get(); 
      set_Get.setservices_type(jsonObject2.getString("fld_category_name")); 
      set_Get.setCity(jsonObject2.getString("fld_city_name")); 
      set_Get.setPincode(jsonObject2.getString("fld_pincode")); 
      set_Get.setSalary(jsonObject2.getString("fld_budget")); 
      set_Get.setFulltime_preference(jsonObject2.getString("fld_full_time_preference")); 
      set_Get.setParttimePreference(jsonObject2.getString("fld_part_time_preference")); 
      set_Get.setAvailabiliy(jsonObject2.getString("fld_availability")); 
      set_Get.setExperience(jsonObject2.getString("fld_exp_from")+"-"+jsonObject2.getString("fld_exp_to")); 
      set_Get.setDate(jsonObject2.getString("fld_posting_date")); 
      set_Get.setVendor_worker_id(jsonObject2.getString("fld_post_your_req_id")); 
      set_Get.setApply_job("Apply"); 
      JSONArray jsonArray2 = jsonObject2.getJSONArray("getjobSpecItems"); 
      for (int j = 0; j < jsonArray2.length(); j++) { 
       JSONObject jsonObject3 = jsonArray2.getJSONObject(j); 
       Grid_specs grid_specs = set_Get.new Grid_specs(); 
       grid_specs.setSpeciality(jsonObject3.getString("fld_sub_category_name")); 
       set_Get.list_Specs.add(grid_specs); 
      } 
      arrayList_jobs.add(set_Get); 

      final Geocoder geocoder = new Geocoder(getActivity()); 
      final String zip = jsonObject2.getString("fld_pincode"); 
      List<Address> addresses = geocoder.getFromLocationName(zip, 1); 
      if (addresses != null && !addresses.isEmpty()) { 
       address = addresses.get(0); 
       String message = String.format("Latitude: %f, Longitude: %f", 
         address.getLatitude(), address.getLongitude()); 

       markerOptions = new MarkerOptions().position(
         new LatLng(address.getLatitude(), address.getLongitude())) 
         .title("Job Posted for:- "+jsonObject2.getString("fld_category_name")); 

       // changing marker color 
       if (arrayList_jobs.get(i).getservices_type().equals("Tutor")){ 
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_tutor)); 
       } 
       if (arrayList_jobs.get(i).getservices_type().equals("Maid")){ 
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_maid)); 
       }if (arrayList_jobs.get(i).getservices_type().equals("Driver")){ 
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_driver)); 
       }if (arrayList_jobs.get(i).getservices_type().contains("Chef")){ 
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_chef)); 
       }if (arrayList_jobs.get(i).getservices_type().equals("Helper")){ 
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_help)); 
       } 
       marker =googleMap.addMarker(markerOptions); 
      } 
     } 

     CameraPosition cameraPosition = new CameraPosition.Builder() 
       .target(new LatLng(latitude, longitude)).zoom(13).build(); 
     googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 
     SearchJobListAdapter adapter = new SearchJobListAdapter(getActivity(), arrayList_jobs, 
       "Show",manager); 
     search_listView.setAdapter(adapter); 
    }catch(Exception e){ 
     e.printStackTrace(); 
    } 

答えて

0

が2メインIを向上させることができる見ること:

1) markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_XXX)。

これは多くの時間がかかり、あなたそれを行うに何回

ソリューションは、uは、たとえば活動を初期化する際のマーカーのすべてのビットマップを作成することです。彼らが多くへの道であり、あなたがそれらをすべて使用するつもりがないことを知っていれば、少なくともそれらをキャッシュすることができます。これにより、速度を上げて

2)実際には1つの場所から別の場所に移動するd設定データを取得することはたくさんあります。リクエストのparseNetworkResponseメソッドで既にこれを行うことができます。そこにマーカーを作成して配列に入れてから、メインスレッド上で反復して地図に追加するだけです。あなたは多くのマーカーを使用してマップを更新する際、ソースhere

最後にも、あなたこれらの2つのことから

@Override 
protected Response<T> parseNetworkResponse(
     NetworkResponse response) { 
    try { 
     String json = new String(response.data, 
     HttpHeaderParser.parseCharset(response.headers)); 
    return Response.success(gson.fromJson(json, clazz), 
    HttpHeaderParser.parseCacheHeaders(response)); 
    } 
    // handle errors 
... 
} 

詳細は、あなたはまだいくつかの問題を持つことができます。このソリューションは、既にマーカーがある場合はマーカーを追加しないでください。マーカーを保持し、応答の内容に応じて非表示にする必要があります。隠れたマーカーをたくさん残しておくと地図の速度が遅くなるため、ある時点で地図を消去する必要があります。

+0

ありがとうございましたあなたの貴重なご意見のために、私はあなたの両方のソリューションを試しましたが、何らかのポイントでハングアップしています。スクリーンの前に何らかのプログレスバーを表示してマーカーを更新できますか? – Decveen

+0

もちろんできます。何千ものソリューションとさまざまなスタイルのプログレスバー/インジケータがありますので、1つを選択する必要があります。基本的にはあなたのレイアウトに追加する必要があります、そして、あなたがそれを開始し、マーカーが作成され、あなたがそれを停止する準備ができたらonResponseを要求するとき:) – djodjo

関連する問題

 関連する問題