简体   繁体   中英

Create an array of markers Google Maps V2

Good afternoon. In my application I extract data from the database for the markers on parse.com :

public void ParseQueryMap() {
          ParseQuery query = new ParseQuery("MyObject");
          query.findInBackground(new FindCallback() {
          public void done(List<ParseObject> myObject, ParseException e) {
          if (e == null) {

                    for ( int i = 0; i < myObject.size(); i++) {

                          commGet =  myObject.get(i).getString("Comment");

                          geo1Dub = myObject.get(i).getParseGeoPoint("location").getLatitude();
                          geo2Dub = myObject.get(i).getParseGeoPoint("location").getLongitude();

                         Location aLocation = new Location("first");
                         aLocation.setLatitude(geo1Dub);
                         aLocation.setLongitude(geo2Dub);
                         Location bLocation = new Location("second");
                         bLocation.setLatitude(location.getLatitude());
                         bLocation.setLongitude(location.getLongitude());
                         int distance = (int)aLocation.distanceTo(bLocation);
                              if (distance<rad) {  // where "rad" radius display points
                                  myMap.addMarker(new MarkerOptions().position(new LatLng(geo1Dub,geo2Dub)).title(commGet)                                   .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));     

                               } else {
                               }                                                               

                         }

             } else {
                    Toast.makeText(MainActivity.this, "Error!", Toast.LENGTH_SHORT).show();
              }
          }
      });

I want to create an array of markers to test its size, and if it is zero, then show AlertDialog. That is, I want to know how many bullets I got. Thank you for your help

UPDATE: I want to know how many markers shown on the map

// before loop:
List<Marker> markers = new ArrayList<Marker>();

// inside your loop:
Marker marker = myMap.addMarker(new MarkerOptions().position(new LatLng(geo1Dub,geo2Dub))); //...
markers.add(marker);

// after loop:
markers.size();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM