Google地图自定义标记仅添加一次

时间:2018-05-24 10:22:01

标签: android google-maps view marker geofire

我正在尝试为我的应用创建自定义标记,我试图仅显示来自特定类别的用户。所以我使用了一个查询并过滤了数据。但是当我尝试在谷歌地图上标记它们并调用返回我的customView位图的方法时,它只返回一个位图,并且谷歌地图上只显示一个标记。它们中的任何一个都是不可见的

下面是我试过的

    geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
    @Override
    public void onKeyEntered(String key, GeoLocation location) {
        UIDLocation.put(key,location);
       // mMap.addMarker(new 
    MarkerOptions().position(myPosition).title("Start"));
         marker = mMap.addMarker(new MarkerOptions().position(new 
    LatLng(location.latitude, location.longitude)).title(key));
        markers.put(key, marker);

    }



   View child;
   //MarkeringMap is called when someone click on card which contains the 
   category names
   public void MarkeringMap(String string){ 
   child = getLayoutInflater().inflate(R.layout.category_tags_items, null);
   Query query = 
  FirebaseDatabase.getInstance().getReference().child("WorkMen")
  .orderByChild("subcategory").startAt(string).endAt(string + 
  "\uf8ff").limitToLast(50);
  query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if(dataSnapshot.exists()) {
                Toast.makeText(getActivity(),"there is 
  something",Toast.LENGTH_SHORT).show();
            }  
            for (DataSnapshot usersnapshot : dataSnapshot.getChildren()) {               
                Users users = usersnapshot.getValue(Users.class);
                usersLists.add(users);
                Toast.makeText(getActivity(),users.getName()+"this is 
     username ",Toast.LENGTH_SHORT).show();
               String keystring =  usersnapshot.getKey();
                for (Map.Entry<String,GeoLocation> entry : 
    UIDLocation.entrySet())
                {
                    Marker marker = markers.get(entry.getKey());
                    if (marker != null) {
                        marker.setVisible(false);                          
                                }   
                               if (keystring.equals(entry.getKey())){
                                   Users user1 = 
       usersnapshot.getValue(Users.class);
                                   String s = user1.getName();
                                   Toast.makeText(getActivity(),s+"this is 
       name  of key",Toast.LENGTH_SHORT).show();
                                   Bitmap b = getMarkerImage(child,s);
                                   Marker marker1 = 
      markers.get(entry.getKey());
                                   if (marker1 != null) {
                                       marker1.setVisible(true);
  //marker.setIcon(BitmapDescriptorFactory.fromResource 
// (R.drawable.locationmarker));

   marker1.setIcon(BitmapDescriptorFactory.fromBitmap(b));                                
                                   }                                      
                    }
                }                  
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
   }





  public Bitmap getMarkerImage(View view,String  name){
    TextView textView1 = 
    (TextView)view.findViewById(R.id.tag_Category_name);
       textView1.setText(name);
       Drawable myDrawable = 
    getResources().getDrawable(R.drawable.default_avatar);
    view.measure(View.MeasureSpec.UNSPECIFIED, 
    View.MeasureSpec.UNSPECIFIED);
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.buildDrawingCache();
    Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), 
   view.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN);
    Drawable drawable = view.getBackground();
    if (drawable != null)
        drawable.draw(canvas);
    view.draw(canvas);
    return bitmap;

}

0 个答案:

没有答案