2016-12-12 4 views
-1

J'essaye de faire un PolyGon cliquable.Même j'ai essayé toute la méthode qui a déjà répondu dans ce StackOverFlow. Mais rien n'est travaillé. Mon code est le suivant,En cliquant sur l'événement de PolyGon dans GoogleMap

JSONObject jsonObj = new JSONObject(result); 
        final JSONArray jsonArray = jsonObj.getJSONArray("zones"); 
        int i; 

        System.out.println("PolyGon---> Response jsonArray " + jsonArray); 
        for (i = 0; i < jsonArray.length(); i++) { 
         JSONArray jsonArrayPoly = jsonArray.getJSONObject(i).getJSONArray("coordinates"); 
         System.out.println("PolyGon---> Response coordinates " + jsonArrayPoly); 
         polygonOptions = new PolygonOptions(); 
         polygonOptions.strokeColor(Color.BLACK); 
         polygonOptions.strokeWidth(2); 
         polygonOptions.fillColor(getResources().getColor(R.color.zone)); 
         for (int j = 0; j < jsonArrayPoly.length(); j++) { 
          JSONObject jsonCoordinate = jsonArrayPoly.getJSONObject(j); 
          System.out.println("PolyGon---> Response lat " + jsonCoordinate.getDouble("lat") + " ----> Long"); 
          polygonOptions.add(new LatLng(jsonCoordinate.getDouble("lat"), jsonCoordinate.getDouble("lng"))); 
         } 

         googleMap.addPolygon(polygonOptions); 

        } 

        polygonOptions.clickable(true); 

        googleMap.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() { 
         public void onPolygonClick(Polygon polygon) { 
          Toast.makeText(getApplicationContext(), "Problem reading list of markers.", Toast.LENGTH_LONG).show(); 

         } 
        }); 

Votre réponse est d'être plus apprécié.

Répondre

1

Définissez votre PolygonOptions.clickable avant d'ajouter votre polygone à la carte:

polygonOptions.clickable(true); 
googleMap.addPolygon(polygonOptions); 
+0

Dans le code que vous avez publié 'polygonOptions.clickable (true);' 'est après googleMap.addPolygon (polygonOptions);' – antonio

+0

Oui ... Je vous en remercie .Merci –