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));
}
}