Salut tous le monde,
euh, comme il indique le titre, je voudrais placer plusieurs marqueurs sur le google map, les marqueurs seront sur des points d'une base de données (j'utilise un fichier php pour la connexion à la base et le format JSON pour stocker les résultats), j'ai utilisé le code ci dessous, mais il m'affiche qu'un seul marqueur que dois-je faire ??
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
 
package projet.newnew;
 
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
 
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.*;
 
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
public class MyMapView extends MapView {
 
	private LayoutInflater factory = null;
	 private View alertDialogView = null;
	 private AlertDialog.Builder adb,show;
	private long lastTouchTime = -1;
	GeoPoint p = null;
	Geocoder geoCoder;
	Bundle savedInstanceState;
	public MyMapView(Context context, AttributeSet attrs) {
		super(context, attrs);
 
		factory = LayoutInflater.from(context);
        adb = new AlertDialog.Builder(context);
		show = new AlertDialog.Builder(context);
        geoCoder = new Geocoder(context);
        List<Overlay> listOfOverlays = this.getOverlays();
        MapController mc = this.getController();
        listOfOverlays.clear();
 
        InputStream is = null;
        String result = "";
	    //http post
	    try
	    {
	    	HttpClient httpclient = new DefaultHttpClient();
	    	HttpPost httppost = new HttpPost("http://10.0.2.2/PFEBD/GetAllLieu.php");
	    	HttpResponse response = httpclient.execute(httppost);
	    	HttpEntity entity = response.getEntity();
	    	is = entity.getContent();
	    }
	    catch(Exception e)
	    {
	    	System.out.println( "Error in http connection "+e.toString());
	    }	
	    //convert response to string
	    try
	    {
	    	BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
	    	StringBuilder sb = new StringBuilder();
	    	String line = null;
	    	while ((line = reader.readLine()) != null)
	    	{
	    		sb.append(line + "\n");
	    	}
	    	System.out.println( sb);
	    	is.close();
	    	result=sb.toString();
	    }
	    catch(Exception e)
	    {
	    	System.out.println("Error converting result "+e.toString());
	    }
	    try
	    {
	    	JSONArray jArray = new JSONArray(result);
	    	int i = 0;
	    	while((i < jArray.length()))
	    	{
	    		JSONObject json_data = jArray.getJSONObject(i);
	    		String type = json_data.getString("Type");
	    		String longi = json_data.getString("Longitude");
	    		String lat = json_data.getString("Latitude");
	    		String creepar = json_data.getString("CreePar");
	    		String desc = json_data.getString("Description");
 
	    		 double lati = Double.parseDouble(lat);
	    	    double lng = Double.parseDouble(longi);
 
	    	        p = new GeoPoint(
	    	            (int) (lati * 1E6), 
	    	            (int) (lng * 1E6));
 
	    	        MapOverlay mapOverlay = new MapOverlay();
	    	        listOfOverlays.add(mapOverlay);  
	    	        mc.animateTo(p);    
	    	        this.postInvalidate();
	    	        System.out.println(lati+" "+ lng+"\n");
 
	    	        i++;
	    	}
	    }
	    catch(JSONException e)
	    {
	    	System.out.println( "Error parsing data "+e.toString());
	    }
	}
 
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if (ev.getAction() == MotionEvent.ACTION_DOWN) {
			long thisTime = System.currentTimeMillis();
			if (thisTime - lastTouchTime < 250) {
				// Double tap
 
				 p = this.getProjection().fromPixels(
	                     (int) ev.getX(),
	                     (int) ev.getY());
 
				System.out.println( p.getLatitudeE6() / 1E6 + "," + 
                        p.getLongitudeE6() /1E6);
		        alertDialogView = factory.inflate(R.layout.ajoutdumap, null);
		          adb.setView(alertDialogView);
		          adb.setTitle("Ajouter Point ?");
 
		          final EditText ETADesc = (EditText) alertDialogView.findViewById(R.id.etd);
		          final CheckBox CBAMaPosition = (CheckBox) alertDialogView.findViewById(R.id.checkBox1);
		          final  CheckBox CBAAccident = (CheckBox) alertDialogView.findViewById(R.id.checkBox2);
		          final    CheckBox CBARest = (CheckBox) alertDialogView.findViewById(R.id.checkBox3);
		          final     CheckBox CBAHotel = (CheckBox) alertDialogView.findViewById(R.id.checkBox4);
		          adb.setPositiveButton("Ajouter", new DialogInterface.OnClickListener() {
		              public void onClick(DialogInterface dialog, int id) {
 
		            	  int i = 0;
							String A = null;
	    					if(CBAAccident.isChecked() == true)
	    					{
	    						A = "Accident";
	    						i++;
	    					}
	    					if(CBAHotel.isChecked() == true)
	    					{
	    						A = "Hotel";
	    						i++;
	    					}
	    					if(CBARest.isChecked() == true)
	    					{
	    						A = "Restaurent";
	    						i++;
	    					}
	    					if(CBAMaPosition.isChecked() == true)
	    					{
	    						A = "Position";
	    						i++;
	    					}
	    					if(i == 1)
	    					{
	    						ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
	        			        nameValuePairs.add(new BasicNameValuePair("Longitude",p.getLongitudeE6() / 1E6+""));
	        			        nameValuePairs.add(new BasicNameValuePair("Latitude",p.getLatitudeE6() / 1E6+""));
 
	        					List<Address> results;
 
	        			        nameValuePairs.add(new BasicNameValuePair("Adresse",""));
	        			        nameValuePairs.add(new BasicNameValuePair("Description",ETADesc.getText().toString()));
	        			        nameValuePairs.add(new BasicNameValuePair("CreePar",""));
	        			        nameValuePairs.add(new BasicNameValuePair("Type",A));
	        			       try
	        			        {
	        			            HttpClient httpclient = new DefaultHttpClient();
	        			            HttpPost httppost = new HttpPost("http://10.0.2.2/PFEBD/AjoutLieu.php");
	        			            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
	        			            HttpResponse response = httpclient.execute(httppost);		  
	        			        }
	        			        catch(Exception e)
	        			        {
	        			            System.out.println( "Error in http connection "+e.toString());
	        			        }
	    					}
	    					else
	    					{
	    						alertbox("Erreur", "Choix incorrect");
	    					}
		             }
		         });
		          adb.setNegativeButton("No", new DialogInterface.OnClickListener() {
		              public void onClick(DialogInterface dialog, int id) {
		                   dialog.cancel();
		              }
		          });
		          adb.show();
				lastTouchTime = -1;
			} else {
				// Too slow 
				lastTouchTime = thisTime;
			}
		}
 
		return super.onInterceptTouchEvent(ev);
	}
 
	class MapOverlay extends com.google.android.maps.Overlay
    {
        @Override
        public boolean draw(Canvas canvas, MapView mapView, 
        boolean shadow, long when) 
        {
            super.draw(canvas, mapView, shadow);                   
 
            //---translate the GeoPoint to screen pixels---
            Point screenPts = new Point();
            mapView.getProjection().toPixels(p, screenPts);
            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(
                getResources(), R.drawable.pushpin);            
            canvas.drawBitmap(bmp, screenPts.x-45, screenPts.y-55, null);         
            return true;
        }
    }
 
	protected void alertbox(String title, String mymessage)  
	{  
 
		show.setMessage(mymessage)  
	   .setTitle(title)  
	   .setCancelable(true)  
	   .setIcon(R.drawable.negative)
	   .setNeutralButton(android.R.string.ok,  
	      new DialogInterface.OnClickListener() {  
	      public void onClick(DialogInterface dialog, int whichButton){}  
	      }) 
	   .show();  
	}
 
}
MERCI d'avance