IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Problème d'exécution d'AsyncTask


Sujet :

Android

  1. #1
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut Problème d'exécution d'AsyncTask
    Bonsoir tout le monde,
    J'ai développée une application qui permet d'afficher des marqueurs autour de la position de l'utilisateur à partir des données récupérées d'un serveur .
    Il n'y a pas des erreurs dans le logcat et la position de l'utilisateur s'affiche mais les marqueurs ne s'affichent pas .
    Voila mon MainActivity.java:


    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
    package com.example.recherche_restaurant;
     
    import java.io.InputStream;
     
    import java.util.List;
     
     
     
     
     
     
    import org.apache.http.HttpEntity;
    import org.json.JSONArray;
    import org.json.JSONException;
     
    import org.json.JSONObject;
     
     
    import com.example.recherche_restaurant.R;
    import com.example.recherche_restaurant.JsonParser;
    import com.example.recherche_restaurant.ListItimizedOverlay;
     
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapController;
    import com.google.android.maps.MapView;
    import com.google.android.maps.MyLocationOverlay;
    import com.google.android.maps.Overlay;
    import com.google.android.maps.OverlayItem;
     
     
     
     
    import android.graphics.drawable.Drawable;
     
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
     
    import android.os.AsyncTask;
    import android.os.Bundle;
     
    import android.view.KeyEvent;
     
     
     
    public class MainActivity extends  MapActivity  implements
    LocationListener {
     
     
     
    	private static double lat = 0;
        private static double lng = 0;
     
        private static final String TAG_results = "results";
    	private static final String TAG_geometry = "geometry";
    	private static final String TAG_location = "location";
    	private static final String TAG_lat = "lat";
    	private static final String TAG_lng = "lng";
    	JSONArray contacts = null;
     
        private MapView mapView = null;
        private LocationManager lm = null;
     
     
        private MapController mc = null;
        private MyLocationOverlay myLocation = null;
     
     
        HttpEntity httpEntity;
        static InputStream is = null;
     
    	static JSONObject jObj = null;
     
    	static String json = "";
    	final String extra_longitude ="";
    	final String extra_latitude =""; 
     
     
     
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.activity_main);
     
     
    	mapView = (MapView) this.findViewById(R.id.mapView);
    	mapView.setBuiltInZoomControls(true);
    	lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
    	lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10, 0, this);
    	lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0,
    		this);
     
     
    	mc = mapView.getController();
    	mc.setZoom(15);
    	myLocation = new MyLocationOverlay(getApplicationContext(), mapView);
    	myLocation.runOnFirstFix(new Runnable() {
    	    public void run() {
    		mc.animateTo(myLocation.getMyLocation());
    		mc.setZoom(17);
    	    }
    	});
     
    	mapView.getOverlays().add(myLocation);
    	myLocation.enableMyLocation();
     
     
     
     
        }
     
     
     
        @Override
        protected void onResume() {
    	super.onResume();
    	myLocation.enableMyLocation();
    	myLocation.enableCompass();
        }
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
    	if (keyCode == KeyEvent.KEYCODE_S) {
    	    mapView.setSatellite(!mapView.isSatellite());
    	    return true;
    	}
    	return super.onKeyDown(keyCode, event);
        }
     
     
    	@Override
    	public void onLocationChanged(Location location) {
    		lat = location.getLatitude();
    		lng = location.getLongitude();
     
    		Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
    		final ListItimizedOverlay itemizedoverlay = new ListItimizedOverlay(drawable,this);
    		final  String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+lat+","+lng +"&radius=500&types=food&name=harbour&sensor=true&key=AIzaSyDxms7wMJorpD9LZVRL9OiozgV1D9wJKxo";
    		new AsyncTask<Void, Void, JSONObject>(){
    			@Override
    		protected JSONObject doInBackground(Void... params) {
    				// instancier la classe JsonParser
    				JsonParser jParser = new JsonParser ();
    				// récupérer le JSONObject à partir de l’url du fichier employes.json
    				JSONObject json = jParser.getJSONFromUrl(url);
     
    				return json;
    			};
     
     
    		protected void onPostExecute(JSONObject json) {
     
    			try {
     
    				// récupérer la liste de tous les employés
    				JSONArray results = json.getJSONArray(TAG_results);
     
    				// parcourir toute la liste des employés
    				for(int i = 0; i < results.length(); i++){
     
    				// récupérer un employé de type JSONObject
    				JSONObject emp = results.getJSONObject(i);
     
    				// récupérer le JSONObject phone qui contient deux items
    				JSONObject geometry = emp.getJSONObject(TAG_geometry);
    				JSONObject location = geometry.getJSONObject(TAG_location);
    				String latitude = location.getString(TAG_lat);
    				String longitude= location.getString(TAG_lng);
    				double b = Double.parseDouble(latitude);
    				double c = Double.parseDouble(longitude);
     
     
    			GeoPoint geoPoint = new GeoPoint((int) (c* 1E6) , (int)(b* 1E6));
    			OverlayItem overlayitem = new OverlayItem(geoPoint, "Hello from", "Tahiti");
    			itemizedoverlay.addOverlayItem(overlayitem);
     
     
    			List<Overlay> mapOverlays = mapView.getOverlays();
    			mapOverlays.add(itemizedoverlay);
     
    			}
    			}
    			catch(JSONException e)
    			{
    				e.printStackTrace();
    			}
    		};
     
    	}.execute();
     
    	}
     
     
     
     
     
    	@Override
    	public void onProviderDisabled(String arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
     
    	@Override
    	public void onProviderEnabled(String arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
     
    	@Override
    	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
    		// TODO Auto-generated method stub
     
    	}
     
     
    	@Override
    	protected boolean isRouteDisplayed() {
    		// TODO Auto-generated method stub
    		return false;
    	}
     
    }

    Pouvez vous m'aider s'il vous plait et merci d'avance .

  2. #2
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    Est ce que tu récupères bien les données ?
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  3. #3
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour,
    Merci pour votre réponse.
    j'arrive à corriger l'erreur .C'était dans mon url qui contient un attribut name qui oblige que les places recherchées ayant ce nom .
    je supprimes alors cette attribut .

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'exécution avec Dec C++
    Par PNL dans le forum C
    Réponses: 20
    Dernier message: 02/10/2005, 03h59
  2. Problème pour exécuter une chaîne de caractères
    Par Pongo dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 02/09/2005, 10h34
  3. Problème d'exécution : 'rtl60.bpl introuvable'
    Par zeddy23 dans le forum EDI
    Réponses: 3
    Dernier message: 27/07/2005, 20h44
  4. Réponses: 5
    Dernier message: 19/04/2005, 08h50
  5. Problème à l'exécution avec wxWindows (compilé avec BCC55)
    Par ShootDX dans le forum Autres éditeurs
    Réponses: 5
    Dernier message: 14/11/2003, 18h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo