【发布时间】:2017-08-18 01:04:20
【问题描述】:
我目前正在通过此插件处理 KML 文件:https://github.com/sushihangover/SushiHangover.Android.Maps.Utils
我正在使用的 KML 文件已通过此 coden-p 成功添加:
var kmlLayer = new KmlLayer(googleMap, Resource.Raw.campus, Android.App.Application.Context);
kmlLayer.AddLayerToMap();
MoveCameraToKml(kmlLayer);
添加后,我运行MoveCameraToKml函数,尝试获取每个点的经纬度,但我在foreach (LatLng latLng in ((KmlLineString)geo).GeometryObject);这一行发生崩溃,错误消息为:object reference not set to an instance of an object
void MoveCameraToKml(KmlLayer kmlLayer)
{
//Retrieve the first container in the KML layer
var container = (KmlContainer)kmlLayer.Containers.Iterator().Next();
//Retrieve a nested container within the first container
container = (KmlContainer)container.Containers.Iterator().Next();
//Retrieve the first placemark in the nested container
var placemark = (KmlPlacemark)container.Placemarks.Iterator().Next();
var geo = placemark.Geometry;
if (geo is KmlLineString)
{
foreach (LatLng latLng in ((KmlLineString)geo).GeometryObject) //object reference not set to an instance of an object
{
System.Diagnostics.Debug.WriteLine(latLng);
}
}
}
知道为什么这会让我崩溃吗?我正在按照上面下载的 nuget 示例进行操作。
这个想法是将 lat、lngs 存储在一个列表中,并使用 PolylineOptions 创建路由。
【问题讨论】:
标签: google-maps xamarin xamarin.android