KMLViewer Apple's example not working

徘徊边缘 提交于 2019-12-01 21:31:52

It looks like KMLViewer can only handle one LineString object per Placemark.

For the route you tried, Google is returning two LineString objects in the "Route" Placemark (the last one in the file). KMLViewer only displays the second (last) LineString segment.

Aside from updating the KMLViewer code to add support for multiple LineString objects per Placemark (which looks like a good exercise), you can try these two workarounds:

Combine the coordinates from the two LineString objects into one LineString. Change:

<Placemark>
    <name>Route</name>
    <description>some cdata stuff here</description>
    <GeometryCollection>
        <LineString><coordinates>coord1 … coordN</coordinates></LineString>
        <LineString><coordinates>coordN+1 … coordK</coordinates></LineString>
    </GeometryCollection>
    <styleUrl>#roadStyle</styleUrl>
</Placemark>

To this:

<Placemark>
    <name>Route</name>
    <description>some cdata stuff here</description>
    <GeometryCollection>
        <LineString><coordinates>coord1 … coordN coordN+1 … coordK</coordinates></LineString>
    </GeometryCollection>
    <styleUrl>#roadStyle</styleUrl>
</Placemark>

The above might only make sense for routes (line segments) that are supposed to be continuous.

Another workaround is to split the "Route" Placemark into multiple placemarks (one for each LineString):

<Placemark>
    <name>Route A</name>
    <description>some cdata stuff here</description>
    <GeometryCollection>
        <LineString><coordinates>coord1 … coordN</coordinates></LineString>
    </GeometryCollection>
    <styleUrl>#roadStyle</styleUrl>
</Placemark>
<Placemark>
    <name>Route B</name>
    <description>some cdata stuff here</description>
    <GeometryCollection>
        <LineString><coordinates>coordN+1 … coordK</coordinates></LineString>
    </GeometryCollection>
    <styleUrl>#roadStyle</styleUrl>
</Placemark>

One issue with this is that the "description" which contains distance and time info will not match the split routes.

Yup. Thanks a lot for your fast response. I've discovered in the morning that the problem is with these tags together (close&open)

</coordinates></LineString><LineString><coordinates>

My plan:

Save the output from URL to a NSString, remove if exists the tags above, afterwards save to a file and send it to KMLParser. I'll get back when i'm finished.

Again thanks a lot for your response.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!