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 affichage map V2


Sujet :

Android

  1. #1
    Membre actif Avatar de janyoura
    Femme Profil pro
    étudiante ingénierie informatique
    Inscrit en
    Mars 2012
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante ingénierie informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 365
    Points : 279
    Points
    279
    Par défaut Problème affichage map V2
    Bonjour,
    En essayant de mettre à jour la version google maps de mon application, j'ai eu un problème;
    j'arrive à afficher la position actuelle et le code fonctionne càd calcul de la distance minimale et l'affichage du marqueur s'effectue mais sur un fond blanc! pas de map, alors que lorsque je clique sur le petit bouton qui m'amène vers ma position, il l'affiche avec la map, non pas sur un fond blanc. ai-je fais une faute lors de la manipulation?
    Merci
    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
    @SuppressLint("NewApi")
    public class TestMap extends Activity implements LocationListener {
     
     
     
     
      private GoogleMap map;
      double latitudemin;
       double longitudemin;
       Marker marker;
     
    	 ArrayList<HashMap<String, String>> centersList;
    	  private static final String TAG_LONG = "longitude";
    	    private static final String TAG_LAT = "latitude";
    	    int indexMin;
    	 // Progress Dialog
    	    private ProgressDialog pDialog;
     
    	    // Creating JSON Parser object
    	    JSONParser jParser = new JSONParser();
     
     
     
    	    // url to get all products list
    	    private static String url_all_products = "http://xxx";
    	 // JSON Node names
    	    private static final String TAG_SUCCESS = "success";
    	    private static final String TAG_PRODUCTS = "centers";
    	    private static final String TAG_PID = "_id";
    	    private static final String TAG_NAME = "name";
    	    private static final String TAG_TEL = "tel";
    	    private static final String TAG_ADDRESS = "address";
    	    private static final String TAG_FIELD = "field";
    	    private static final String TAG_EMAIL = "email";
    	    private static final String TAG_CITY = "city";
     
     
    	    // products JSONArray
    	    JSONArray centers = null;
     
     
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.localisation);
     // Hashmap for ListView
        centersList = new ArrayList<HashMap<String, String>>();
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();
        map.setMyLocationEnabled(true);
        // Loading products in Background Thread
        new LoadAllCenters().execute();
     
     
     
     
      }
     
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
       // getMenuInflater().inflate(R.menu.localisation, menu);
        return true;
      }
      private void setUpMapIfNeeded() {
    	    // Do a null check to confirm that we have not already instantiated the map.
    	    if (map == null) {
    	        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
    	                            .getMap();
    	        // Check if we were successful in obtaining the map.
    	        if (map != null) {
    	            // The Map is verified. It is now safe to manipulate the map.
     
    	        }
    	    }
    	}
     
      private void changeTypeMap() {
    	  //Normal  map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    	  //Hibrid map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    	  // satellite map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
      }
      /**
       * Background Async Task to Load all product by making HTTP Request
       * */
      class LoadAllCenters extends AsyncTask<String, String, String> {
     
          /**
           * Before starting background thread Show Progress Dialog
           * */
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(TestMap.this);
              pDialog.setMessage("Loading Map View. Please wait...");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(false);
              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 Centers: ", json.toString());
     
              try {
                  // Checking for SUCCESS TAG
                  int success = json.getInt(TAG_SUCCESS);
     
                  if (success == 1) {
                      // products found
                      // Getting Array of Products
                      centers = json.getJSONArray(TAG_PRODUCTS);
     
                      // looping through All Products
                      for (int i = 0; i < centers.length(); i++) {
                          JSONObject c = centers.getJSONObject(i);
     
                          // Storing each json item in variable
                          String id = c.getString(TAG_PID);
                          String name = c.getString(TAG_NAME);
                          String tel = c.getString(TAG_TEL);
                          String address = c.getString(TAG_ADDRESS);
                          String field = c.getString(TAG_FIELD);
                          String city = c.getString(TAG_CITY);
                          String email = c.getString(TAG_EMAIL);
                          double longitud = c.getDouble(TAG_LONG);
                          String longitude = Double.toString(longitud);
                          double lati = c.getDouble(TAG_LAT);
                          String latitude = Double.toString(lati);
     
                          // 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, name);
                          map.put(TAG_TEL, tel);
                          map.put(TAG_ADDRESS, address);
                          map.put(TAG_CITY, city);
                          map.put(TAG_FIELD, field);
                          map.put(TAG_EMAIL, email);
                          map.put(TAG_LONG, longitude);
                          map.put(TAG_LAT, latitude);
     
                          // adding HashList to ArrayList
                          centersList.add(map);
     
                      }
                  } 
              } catch (JSONException e) {
                  e.printStackTrace();
              }
     
              return null;
          }
     
          /**
           * After completing background task Dismiss the progress dialog
           * **/
          protected void onPostExecute(String file_url) {
              // dismiss the dialog after getting all products
              pDialog.dismiss();
                  	// calcul distance min
    	      			  int   indexDistancemin = calculDistanceMin();
    	      			//  Log.i(getClass().getName(), "index : " + indexmin);
    	      			   String   latitudemn = centersList.get(indexDistancemin).get(TAG_LAT);
    	      			   double latitudemin = Double.parseDouble(latitudemn);
    	      			    String longitudemn = centersList.get(indexDistancemin).get(TAG_LONG);
    	      			    double longitudemin = Double.parseDouble(longitudemn);
     
    	      			    Log.i(getClass().getName(), "latitude min : " + latitudemin + " longitude min: " + longitudemin);
                  	 // La nouvelle latLng celle de la latitude et longitude min
    	      			  final LatLng latLng = new LatLng(latitudemin, longitudemin);
     
    	      			 marker = map.addMarker(new MarkerOptions().title("center").position(new LatLng(latitudemin, longitudemin)));
    	      			 map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
    	      			 map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    	      		// Zoom in, animating the camera.
    	        		 map.animateCamera(CameraUpdateFactory.zoomIn());
     
          }
     
      }
      public int calculDistanceMin(){
     
    		float[] results = new float[3];
    		//initialisation distance min = distance entre 1èr point de la liste et la localisation actuelle
    		  String latitudeinit = centersList.get(1).get(TAG_LAT);
    	 	  double latitudemin = Double.parseDouble(latitudeinit);
    	 	  String longitudeinit = centersList.get(1).get(TAG_LONG);
    			double longitudemin = Double.parseDouble(longitudeinit);
    		  Log.i(getClass().getName(), "latitude default : " + latitudemin + " longitude default: " + longitudemin);
     
    		Location.distanceBetween(map.getMyLocation().getLatitude(), map.getMyLocation().getLongitude(), microdegrees(latitudemin), microdegrees(longitudemin), results);
    		 float distanceMin = results[0];
     
    		 float dmin = 0;
    		  indexMin = 0;
    		 for (int i = 1 ; i< centersList.size() ; i++){
    			 String latitudei = centersList.get(i).get(TAG_LAT);
    	   		  double latitude = Double.parseDouble(latitudei);
    	   		  String longitudei = centersList.get(i).get(TAG_LONG);
    	   		  double longitude = Double.parseDouble(longitudei);
    		 // GeoPoint point = new GeoPoint(microdegrees(latitudeElmt),microdegrees(longitudeElmt));
    		 //myLocation = new MyLocationOverlay(getApplicationContext(), mapView);
     
    		 Location.distanceBetween(map.getMyLocation().getLatitude(), map.getMyLocation().getLongitude(), microdegrees(latitude), microdegrees(longitude), results);
     
    		   if (results[0] < distanceMin){
    			   distanceMin = results[0];
    			   indexMin = i;
    		   }
    		 }
    		dmin = results[0];
     
    		 return indexMin;
    	 }
     private int microdegrees(double value){
    		return (int)(value*1000000);
    	}
     
    @Override
    public void onLocationChanged(Location location) {
     
     
     
    }
     
    @Override
    public void onProviderDisabled(String provider) {
    	// TODO Auto-generated method stub
     
    }
     
    @Override
    public void onProviderEnabled(String provider) {
    	// TODO Auto-generated method stub
     
    }
     
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    	// TODO Auto-generated method stub
     
    }
    }
    "Scientists dream about doing great things. Engineers do them.”

    La réussite après tant de travail est un sentiment à vivre

    Si ton message est résolu, il y a un bouton qui est fait pour ça :
    Il se trouve tout en bas de la conversation !

    N'oublie pas que si ce message t'as aidé, tu peux voter pour lui en utilisant

  2. #2
    Membre actif Avatar de janyoura
    Femme Profil pro
    étudiante ingénierie informatique
    Inscrit en
    Mars 2012
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante ingénierie informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 365
    Points : 279
    Points
    279
    Par défaut
    est ce faux cette partie:
    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
      protected void onPostExecute(String file_url) {
              // dismiss the dialog after getting all products
              pDialog.dismiss();
              // updating UI from Background Thread
     
                  	// calcul distance min
    	      			  int   indexDistancemin = calculDistanceMin();
    	      			//  Log.i(getClass().getName(), "index : " + indexmin);
    	      			   String   latitudemn = centersList.get(indexDistancemin).get(TAG_LAT);
    	      			   double latitudemin = Double.parseDouble(latitudemn);
    	      			    String longitudemn = centersList.get(indexDistancemin).get(TAG_LONG);
    	      			    double longitudemin = Double.parseDouble(longitudemn);
     
    	      			    Log.i(getClass().getName(), "latitude min : " + latitudemin + " longitude min: " + longitudemin);
                  	 // Récupérer la liste des Overlay ajoutés à la map
    	      			  final LatLng latLng = new LatLng(latitudemin, longitudemin);
     
    	      			 marker = map.addMarker(new MarkerOptions().title("center").position(new LatLng(latitudemin, longitudemin)));
    	      			 map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
    	      			 map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    	      		// Zoom in, animating the camera.
    	        		 map.animateCamera(CameraUpdateFactory.zoomIn());
                      /**
                       * Updating parsed JSON data into ListView
                       * */
     
     
     
     
          }
    "Scientists dream about doing great things. Engineers do them.”

    La réussite après tant de travail est un sentiment à vivre

    Si ton message est résolu, il y a un bouton qui est fait pour ça :
    Il se trouve tout en bas de la conversation !

    N'oublie pas que si ce message t'as aidé, tu peux voter pour lui en utilisant

  3. #3
    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
    As tu bien mis à jour ta GoogleMap ?

    Il faut mettre à jour sa clé :
    Note: The Google Maps Android API v2 uses a new system of managing keys. Existing keys from a Google Maps Android v1 application, commonly known as MapView, will not work with the v2 API.
    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.

  4. #4
    Membre actif Avatar de janyoura
    Femme Profil pro
    étudiante ingénierie informatique
    Inscrit en
    Mars 2012
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante ingénierie informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 365
    Points : 279
    Points
    279
    Par défaut
    j'ai résolu le problème, merci. ce n'était pas un problème de mise à jour clé
    "Scientists dream about doing great things. Engineers do them.”

    La réussite après tant de travail est un sentiment à vivre

    Si ton message est résolu, il y a un bouton qui est fait pour ça :
    Il se trouve tout en bas de la conversation !

    N'oublie pas que si ce message t'as aidé, tu peux voter pour lui en utilisant

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

Discussions similaires

  1. problème affichage google Map android V2
    Par mayssa_salhi dans le forum API standards et tierces
    Réponses: 1
    Dernier message: 22/02/2014, 10h45
  2. Problème affichage Map google
    Par cartman_94 dans le forum API standards et tierces
    Réponses: 19
    Dernier message: 07/02/2014, 14h39
  3. Problém affichage maps view android
    Par othman22222 dans le forum Composants graphiques
    Réponses: 1
    Dernier message: 03/06/2013, 10h23
  4. [IE 8] Problème affichage Google Maps
    Par Sekigawa dans le forum IE
    Réponses: 3
    Dernier message: 08/09/2010, 14h59
  5. [Conseil] Affichage maps + objets
    Par Mathieu.J dans le forum OpenGL
    Réponses: 4
    Dernier message: 04/06/2004, 14h35

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