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 :

Peupler un MapView à partir d'un parseur JSON


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Août 2009
    Messages
    53
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 53
    Par défaut Peupler un MapView à partir d'un parseur JSON
    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);
    			}

  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,

    Pourrais tu nous expliquer ton "ca ne marche pas".

    As tu déboguer ? Sait tu ce qui bloque ?

    Merci de prendre de votre temps à nous expliquer votre problème.

Discussions similaires

  1. Réponses: 0
    Dernier message: 07/08/2013, 21h15
  2. Afficher Graphiques / Diagrammes à partir d'un fichier JSON
    Par glbaa dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 05/12/2011, 15h20
  3. Parseur JSON 2 DOM
    Par azerr dans le forum Format d'échange (XML, JSON...)
    Réponses: 0
    Dernier message: 02/10/2008, 08h45
  4. Peupler une JTable à partir de JDBC
    Par LhIaScZkTer dans le forum Composants
    Réponses: 7
    Dernier message: 21/06/2007, 11h14

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