Bonjour;
J'ai essayé de peupler un GoogleMap par des markers à travers des latitudes et longitudes à partir d'un Json parser...j'ai essayé avec asynctask mais ça marche pas ..voici mon code et merci pour l'aide:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
		@Override
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.map);
 
			// Hashmap for ListView
			magasinsList = new ArrayList<HashMap<String, String>>();
 
			// Loading products in Background Thread
			new LoadAllProducts().execute();
 
		}
		@Override
		protected void onActivityResult(int requestCode, int resultCode, Intent data) {
			super.onActivityResult(requestCode, resultCode, data);
			// if result code 100
			if (resultCode == 100) {
				// if result code 100 is received 
				// means user edited/deleted product
				// reload this screen again
				Intent intent = getIntent();
				finish();
				startActivity(intent);
			}
 
		}
 
		/**
                 * Background Async Task to Load all product by making HTTP Request
                 * */
		class LoadAllProducts extends AsyncTask<String, String, String> {
 
			/**
                         * Before starting background thread Show Progress Dialog
                         * */
			@Override
			protected void onPreExecute() {
				super.onPreExecute();
				pDialog = new ProgressDialog(mapActivity.this);
 
				pDialog.setMessage("Loading");
				pDialog.setIndeterminate(false);
				pDialog.setCancelable(true);
				pDialog.show();
 
			}
 
			/**
                         * getting All products from url
                         * */
			protected String doInBackground(String... args) {
				// Building Parameters
				List<NameValuePair> params = new ArrayList<NameValuePair>();
				// getting JSON string from URL
				JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
 
				// Check your log cat for JSON reponse
				Log.d("All Markets: ", json.toString());
 
				try {
					// Checking for SUCCESS TAG
					int success = json.getInt(TAG_SUCCESS);
 
					if (success == 1) {
						// products found
						// Getting Array of Products
						magasins = json.getJSONArray(TAG_MARKETS);
 
						// looping through All Products
						for (int i = 0; i < magasins.length(); i++) {
							JSONObject c = magasins.getJSONObject(i);
 
							// Storing each json item in variable
							String id = c.getString(TAG_PID);
							String nom = c.getString(TAG_NAME);
							String ville = c.getString(TAG_VILLE);
							String latitude = c.getString(TAG_LATITUDE);
							String longitude = c.getString(TAG_LONGITUDE);
							// creating new HashMap
							HashMap<String, String> map = new HashMap<String, String>();
 
							// adding each child node to HashMap key => value
							map.put(TAG_PID, id);
							map.put(TAG_NAME, nom);
							map.put(TAG_VILLE, ville);
							map.put(TAG_LATITUDE, latitude);
							map.put(TAG_LONGITUDE, longitude);
							// adding HashList to ArrayList
							magasinsList.add(map);
 
 
						}
					} else {
						// no products found
						// Launch Add New product Activity
					//	Intent i = new Intent(getApplicationContext(),
							//	NewProductActivity.class);
						// Closing all previous activities
					//	i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					//	startActivity(i);
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
 
				return null;
 
			}
			/**
                         * After completing background task Dismiss the progress dialog
                         * **/
			protected void onPostExecute(String file_url) {
				/**
                                 * Updating parsed JSON data into ListView
                                 * */
				double latg=Double.parseDouble(TAG_LATITUDE);
     			double longg=Double.parseDouble(TAG_LONGITUDE);
     			final LatLng local = new LatLng(latg,longg);
     			Marker locations = googleMap.addMarker(new MarkerOptions()
                .position(local)
                .title(TAG_NAME)
                .snippet(TAG_VILLE)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.gps)));
//CameraUpdate center=
// CameraUpdateFactory.newLatLng(new LatLng(latitude,longitude));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(5);
 
//googleMap.moveCamera(center);
googleMap.animateCamera(zoom);
			}