将多个标记添加到地图android

时间:2015-11-26 14:07:52

标签: android json marker

我从json那里读取细节,想在地图上钉一个以上的位置。我试过这个。 因此,我想要检索我成功完成的数据,将其添加到列表中,以便我可以在地图上准备好活动

    try {
        JSONObject jsonObj = new JSONObject(myJSON);
        peoples = jsonObj.getJSONArray(TAG_RESULTS);


        for (int i = 0; i < peoples.length(); i++) {
            JSONObject c = peoples.getJSONObject(i);
            String id = c.getString(TAG_ID);
            String name = c.getString(TAG_NAME);
            final String business_email = c.getString(TAG_BUSINESS_EMAIL);
            final String offerType = c.getString(TAG_TYPE);
            String offerDescription = c.getString(TAG_DESCRIPTION);
            String businessId = c.getString(TAG_BUSINESS_ID);
             address = c.getString(TAG_LOCATION);
            Offer a=new Offer();
            a.setLocation(address);

            offers.add(a);
            // lists.setText(address);
         //   lists.setText(this.offers.get(i).getLocation());

        }


    } catch (JSONException e) {
        e.printStackTrace();
    }

}

关于地图就绪方法

    LatLng ireland = new LatLng(53.344104, -6.2674937);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ireland,12));

    Geocoder gc = new Geocoder(this);
    List<Address> list = null;
    for (int i = 0; i < offers.size(); i++) {
     //String address="Aungier Street,Dublin";
         lists.setText(address);

        String address = this.offers.get(i).getLocation();
        try {
            list = gc.getFromLocationName(address, 1);
            Address add = list.get(0);
            double lat = add.getLatitude();
            double lng = add.getLongitude();
            Marker marker = mMap.addMarker(new MarkerOptions()
                    .position(new LatLng(lat, lng))
                    .title("")
                    .snippet(""));

            markers.add(marker);

        } catch (IOException e) {
            e.printStackTrace();
        }

任何建议都将受到赞赏。

0 个答案:

没有答案