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

API standards et tierces Android Discussion :

Problème de géolocalisation


Sujet :

API standards et tierces Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    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
    Par défaut Problème de géolocalisation
    Bonjour,
    Je suis débutante dans le développement android . J'ai crée une application qui récupère la longitude et la latitude de l'utilisateur et les envoie dans une requête au serveur google api places afin de chercher les endroits publiques autour de l'utilisateur.Les résultats de ce requête doivent être affichées sous forme des marqueurs sur la carte . Il n'y a pas des erreurs dans le logcat mais lorsque je modifie la longitude et la latitude de l'utilisateur , les marqueurs ne s'affichent pas sur la carte .
    Aidez_moi s'il vous plait et merci d'avance . Voici mes classes java:

    JsoParser.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
    package com.example.recherche_restaurant;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.UnsupportedEncodingException;
     
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import android.util.Log;
     
    public class JsonParser {
    	static InputStream is = null;
     
    	static JSONObject jObj = null;
     
    	static String json = "";
     
     
    	// Constructeur de notre classe
    	public JsonParser() {
     
    	}
     
    	public JSONObject getJSONFromUrl(String url) {
     
    	// début de la requête http
    	try {
     
    	// faire appel à defaultHttpClient
    	DefaultHttpClient httpClient = new DefaultHttpClient();
     
    	HttpPost httpPost = new HttpPost(url);
     
    	HttpResponse httpResponse = httpClient.execute(httpPost);
     
    	HttpEntity httpEntity = httpResponse.getEntity();
     
    	is = httpEntity.getContent();
     
    	} catch (UnsupportedEncodingException e) {
     
    	e.printStackTrace();
     
    	} catch (ClientProtocolException e) {
     
    	e.printStackTrace();
     
    	} catch (IOException e) {
     
    	e.printStackTrace();
     
    	}
     
    	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");
     
    	}
     
    	is.close();
     
    	json = sb.toString();
     
    	} catch (Exception e) {
     
    	Log.e("Buffer Error", "Error converting result " + e.toString());
     
    	}
     
    	// convertir le résultat qui est sous format d'un String en un JSONObject
    	try {
     
    	jObj = new JSONObject(json);
     
    	} catch (JSONException e) {
     
    	Log.e("JSON Parser", "Error parsing data " + e.toString());
     
    	}
     
    	// retourner un JSONObject
    	return jObj;
     
    	} 
    }
    ListItimizedOverlay.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
    package com.example.recherche_restaurant;
     
    import java.util.ArrayList;
     
    import android.app.AlertDialog;
    import android.content.Context;
    import android.graphics.drawable.Drawable;
     
    import com.google.android.maps.ItemizedOverlay;
    import com.google.android.maps.OverlayItem;
     
    public class ListItimizedOverlay extends ItemizedOverlay<OverlayItem> {
     
    	private Context context;
    	private ArrayList<OverlayItem> arrayListOverlayItem = new ArrayList<OverlayItem>();
    	public ListItimizedOverlay(Drawable defaultMarker) {
    		super(boundCenterBottom(defaultMarker));
    		// TODO Auto-generated constructor stub
    	}
    	public ListItimizedOverlay(Drawable defaultMarker, Context pContext) 
    	{
    	  super(boundCenterBottom(defaultMarker));
    	  this.context = pContext;
    	}
     
    	@Override
    	protected OverlayItem createItem(int i) {
    		// TODO Auto-generated method stub
    				return arrayListOverlayItem.get(i);
    	}
     
    	@Override
    	public int size() {
    		// TODO Auto-generated method stub
    		return arrayListOverlayItem.size();
    	}
    	@Override
    	protected boolean onTap(int index) 
    	{
    	  OverlayItem item = arrayListOverlayItem.get(index);
    	  AlertDialog.Builder dialog = new AlertDialog.Builder(context);
    	  dialog.setTitle(item.getTitle());
    	  dialog.setMessage(item.getSnippet());
    	  dialog.show();
    	  return true;
    	}
     
     
    	public void addOverlayItem(OverlayItem overlay) 
    	{
    		arrayListOverlayItem.add(overlay);
    	    populate();
    	}
     
    }

    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
    package com.example.recherche_restaurant;
     
    import java.io.InputStream;
     
     
     
     
     
     
    import org.apache.http.HttpEntity;
    import org.json.JSONArray;
     
    import org.json.JSONObject;
     
     
    import com.example.recherche_restaurant.R;
     
    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 android.content.Intent;
     
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
     
    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;
     
    	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, 10000, 0, this);
    	lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0,
    		this);
     
     
    	mc = mapView.getController();
    	mc.setZoom(19);
     
    	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();
     
    		Intent intent = new Intent(MainActivity.this, Marqueur .class);
    		intent.putExtra(extra_longitude, Double.toString(lng));
    		intent.putExtra(extra_latitude, Double.toString(lat));
    		startActivity(intent);
    	}
     
     
     
     
     
    	@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;
    	}
     
    }

    Marqueur.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
    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.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.Overlay;
    import com.google.android.maps.OverlayItem;
     
    import android.os.AsyncTask;
    import android.os.Bundle;
     
    import android.content.Intent;
    import android.graphics.drawable.Drawable;
     
     
    public class Marqueur extends MapActivity {
    	final String extra_longitude ="";
    	final String extra_latitude =""; 
    	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";
    	 private MapView mapView = null;
     
    	 HttpEntity httpEntity;
    	    static InputStream is = null;
     
    		static JSONObject jObj = null;
     
    		static String json = "";
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_marqueur);
    		  Intent intent = getIntent();
    		  if (intent != null) {
    			  mapView = (MapView) this.findViewById(R.id.mapView);
     
    			 double  lat= Double.parseDouble(intent.getStringExtra(extra_longitude));
    			 double  lng=Double.parseDouble(intent.getStringExtra(extra_latitude));
     
    				getData(lat,lng);
    		  }}
    				private void getData(Double latitude, Double longitude) {
    				final  String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+latitude+","+longitude+"&radius=500&types=food&name=harbour&sensor=true&key=AIzaSyDxms7wMJorpD9LZVRL9OiozgV1D9wJKxo";
    				Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
    				final ListItimizedOverlay itemizedoverlay = new ListItimizedOverlay(drawable,this);
    			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) (b* 1E6) , (int)(c* 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
    	protected boolean isRouteDisplayed() {
    		// TODO Auto-generated method stub
    		return false;
    	}
     
    }

  2. #2
    Expert confirmé

    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
    Par défaut
    Bonjour,

    Est ce que tu passes bien à cet endroit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    List<Overlay> mapOverlays = mapView.getOverlays();
    				mapOverlays.add(itemizedoverlay);
    ?

    Et est ce que ta position s'affiche bien sur la mapview ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    mapView.getOverlays().add(myLocation);
    	myLocation.enableMyLocation();

  3. #3
    Membre confirmé
    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
    Par défaut
    Bonsoir ,
    Merci bien pour votre aide , la position de l'utilisateur s'affiche sur la mapview lorsque je change la longitude et la latitude de l'émulateur .
    J'ai testé ce code avec un exemple d'url qui se trouve dans le site de google développeurs et ça marche bien et les marqueurs s'affichent.
    Le problème c'est lorsque je mets la longitude et la latitude de mon émulateur. Et merci d'avance.

  4. #4
    Expert confirmé

    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
    Par défaut
    Essaye de passer en ligne de commande au lieu du DDNS , des fois celui ci bogue.

    Depuis le shell:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    geo fix <longitude value> <latitude value>
    http://developer.android.com/guide/t...trategies.html

  5. #5
    Membre confirmé
    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
    Par défaut
    Bonsoir Feanorin,
    Grand merci pour votre aide .
    J'ai essayée ce que vous avez dit mais dans le console lorsque je tapes
    telnet localhost 5554
    ,l'erreur
    telnet n'est pas reconnue en tant que commande interne ou externe , programme exécutable ou un fichier de commandes
    malgré que j'exécutes la commande d'après le dossier tools de mon sdk .
    Une autre fois merci bien pour votre aide . Avez_vous des idées à propos cette erreur ? et merci beaucoup.

  6. #6
    Membre confirmé
    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
    Par défaut
    Bonsoir Feanorin,
    Merci beaucoup pour votre aide j'ai pu changer la longitude et la latitude de mon émulateur d'après le console . Mais toujours les marqueurs ne s'affichent pas .
    Voici mon code de test pour laquelle les marqueurs s'affichent :
    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
    package com.example.test_serveur;
     
    import android.os.Bundle;
    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 android.graphics.drawable.Drawable;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.os.AsyncTask;
     
    import android.view.KeyEvent;
    import android.widget.Toast;
     
    import com.example.test_serveur.ListItimizedOverlay;
    import com.example.test_serveur.R;
    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;
     
     
     
    public class MainActivity extends  MapActivity  implements
    LocationListener {
     
     
     
    	private static String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=true&key=AIzaSyDxms7wMJorpD9LZVRL9OiozgV1D9wJKxo";
    	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 double lat = 0;
        private double lng = 0;
        private MapController mc = null;
        private MyLocationOverlay myLocation = null;
        HttpEntity httpEntity;
        static InputStream is = null;
     
    	static JSONObject jObj = null;
     
    	static String json = "";
     
     
        @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, 10000, 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();
     
    	getData();
        }
    	private void getData() {
    		Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
    		final ListItimizedOverlay itemizedoverlay = new ListItimizedOverlay(drawable,this);
    	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
        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();
    		Toast.makeText(
    			getBaseContext(),
    			"Location change to : Latitude = " + lat + " Longitude = "
    				+ lng, Toast.LENGTH_SHORT).show();
    		GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
    		mc.animateTo(p);
    		mc.setCenter(p);
     
    	}
     
     
    	@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;
    	}
     
     
    }
    Les deux autres classes JsonParser.java et ListItimizedOverlay.java sont les mêmes . J'espères que vous m'aidez et merci d'avance.

Discussions similaires

  1. Problème de géolocalisation inversée
    Par _Tracker_ dans le forum IGN API Géoportail
    Réponses: 8
    Dernier message: 12/09/2019, 10h23
  2. Problème de géolocalisation android
    Par android59 dans le forum API standards et tierces
    Réponses: 18
    Dernier message: 14/01/2014, 12h14
  3. [Google Maps] Problème de géolocalisation au-delà de 11 points
    Par ledisciple dans le forum APIs Google
    Réponses: 3
    Dernier message: 22/04/2012, 11h07
  4. Probléme sur géolocalisation
    Par petit'louise dans le forum API standards et tierces
    Réponses: 17
    Dernier message: 22/02/2011, 14h07

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