1
我讀谷歌Android地圖API - 訪問KML容器在KML文件中檢索從嵌套集裝箱數據
https://developers.google.com/maps/documentation/android-api/utility/kml#clear
要訪問的是嵌套在一個KmlLayer或KmlContainer容器:
Iterable containers = layer.getContainers();
public void accessContainers(containers) {
for (KmlContainer container : containers) {
// Do something to container
if (container.hasContainers()) {
accessContainers(container.getContainers());
}
}}
我應該在哪裏把這個方法的程序?
在演示progrma,我發現這些,但我仍然不知道如何使用它
//Retrieve the first container in the KML layer
KmlContainer container = kmlLayer.getContainers().iterator().next();
//Retrieve a nested container within the first container
container = container.getContainers().iterator().next();
這裏是我的程序
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
private GoogleMap mMap;
private KmlLayer layer;
private KmlContainer container;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap)
{
mMap = googleMap;
try {
layer = new KmlLayer(mMap, R.raw.canberra, getApplicationContext());
layer.addLayerToMap();
containers = layer.getContainers();
} catch (XmlPullParserException e)
{e.printStackTrace();}
catch (IOException e)
{ e.printStackTrace();}
LatLng sydney = new LatLng(-34, 151);
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}