面对通过DynamoDb获取多个标记的问题

时间:2017-10-24 12:39:23

标签: android google-maps amazon-dynamodb google-maps-markers kml

我是android的新手并且在基于地图的应用程序上工作,我想要显示多个标记(大约1000或更多),我已经完成了Dynamo db的所有步骤并将结果存储在列表中。现在,当我搜索在地图中显示多个标记时,我有一个解决方案,我必须将数据存储在数组中,然后将其放入循环中。我将标记存储在字符串X,Y和XY中。 我想在地图上显示。请仔细阅读代码,让我知道如何获取X,Y和XY的值。

Settlements.java

private String X;
private String Y;
private String XY;
private String "AreaName"

@DynamoDBHashKey(attributeName = "AreaName")
public String getAreaName() {
    return AreaName;
}

public void setAreaName(String AreaName) {
    this.AreaName = AreaName;
}

@DynamoDBAttribute(attributeName = "X")
public String getX() {
    return X;
}

public void setX(String x) {
    X = x;
}

@DynamoDBAttribute(attributeName = "Y")
public String getY() {
    return Y;
}

public void setY(String y) {
    Y = y;
}

@DynamoDBAttribute(attributeName = "XY")
public String getXY() {
    return XY;
}

public void setXY(String XY) {
    this.XY = XY;
}

这是我的MainActivity。

 public class NavigationDrawerPeaceNow extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
        ImageView imageView;
        OutpostsTable outpostsTable;
        private GoogleMap googleMap;
        private Context mContext;
        private List<SettlementsTable> lstSettlements = new ArrayList<>();

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_navigation_drawer_peace_now);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            imageView = (ImageView) findViewById(R.id.layersiv);
            setSupportActionBar(toolbar);

            DDBExecutor.getInstance().getAllSettlements(mContext, new DDBExecutor.OnResponseListener() {
                @Override
                public void onResponse(Object result, String message) {
                    lstSettlements.addAll((List<SettlementsTable>) result);



                    }
                }
            });


            ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMapAsync(new OnMapReadyCallback() {
                @Override
                public void onMapReady(GoogleMap googleMap) {
                    try {
                        KmlLayer kmlLayer = new KmlLayer(googleMap, R.raw.settlements, getApplicationContext());
                        kmlLayer.addLayerToMap();
                        KmlLayer kmlLayer1 = new KmlLayer(googleMap, R.raw.outposts, getApplicationContext());
                        kmlLayer1.addLayerToMap();
                        KmlLayer kmlLayer2 = new KmlLayer(googleMap, R.raw.settlements_in_pal_nghbrhd_styled, getApplicationContext());
                        kmlLayer2.addLayerToMap();

                    } catch (XmlPullParserException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    LatLng israel = new LatLng(31.0461, 34.8516);
                    googleMap.addMarker(new MarkerOptions().position(israel).title("israel"));

                    googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
                    CameraPosition camPos = new CameraPosition.Builder().target(new LatLng(31.0461, 34.8516)).zoom(8).tilt(70).build();
                    CameraUpdate camUpd3 = CameraUpdateFactory.newCameraPosition(camPos);
                    googleMap.animateCamera(camUpd3);
                }


            });

1 个答案:

答案 0 :(得分:0)

为什么不使用SettlementsTable

列表执行此操作
for (SettlementsTable settlementsTable :lstSettlements) {
            LatLng latLng=new LatLng(Double.parseDouble(settlementsTable.getX()),Double.parseDouble(settlementsTable.getY()));
            googleMap.addMarker(new MarkerOptions().position(latLng).title(settlementsTable.getXY()));
        }