簡體   English   中英

創建一個標記數組Google Maps V2

[英]Create an array of markers Google Maps V2

下午好。 在我的應用程序中,我從數據庫中提取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();
              }
          }
      });

我想創建一個標記數組來測試它的大小,如果它是零,則顯示AlertDialog。 也就是說,我想知道我得了多少子彈。 謝謝您的幫助

更新:我想知道地圖上顯示了多少個標記

// 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM