【问题标题】:Create an array of markers Google Maps V2创建一组标记 Google Maps V2
【发布时间】:2013-03-15 13:29:51
【问题描述】:

下午好。在我的应用程序中,我从数据库中为 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。也就是说,我想知道我得到了多少子弹。谢谢你的帮助

更新:我想知道地图上显示了多少标记

【问题讨论】:

  • 问题是......?
  • 当您为 List myObject 的每个条目添加标记时,我认为您有 myObject.getSize() 标记。
  • myObject.getSize() 显示数据库中的记录数。我计划继续计算我的位置和基地点之间的距离,现在我需要知道我旁边有哪些标记,哪些没有。
  • 我需要知道地图上标记的数量

标签: android arrays google-maps-markers


【解决方案1】:
// 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();

【讨论】:

  • 如何在地图上显示它们?我只能显示数组中的最后一个
【解决方案2】:
List<LatLng> plots = new ArrayList();

//get your coordinates and add them to the list of plots
plots.add(new LatLng(latitude,longitude));

plots.forEach(plot->{
    MarkerOptions marker = new MarkerOptions().position(plot).title("My 
    Position");
    googleMap.addMarker(marker);
});

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2013-08-23
  • 1970-01-01
  • 2013-06-14
  • 1970-01-01
  • 1970-01-01
  • 2013-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多