So, I've got a class with contains a NSMutableArray of CLLocation's, and a name.
Now I want to save them to KML, ideally as a track (or , so I can use the file to display the locations traveled.)
How would I go about this?
I don't expect code, more guidance (I'm new to Objective-C and KML, so got a lot to learn! :) )
I haven't used either of these, but here's a couple of libraries that turned up in a search:
http://github.com/incanus/Simple-KML/
http://developmentseed.org/blog/2010/aug/12/kml-parsing-library-released-apples-ios-platform
Edit: it looks like both those libraries are parsers, not writers. You may have to create your own writer.
I'd say that using either of these libraries would save you a lot of time. That said, have a look at how KML is formed. It's just XML and making a track is really easy. Here's an example:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1" xmlns:trails="http://www.google.com/kml/trails/1.0">
<Document>
<name>RK_Running.kml</name>
<Placemark>
<name>Running 12/9</name>
<Style>
<LineStyle>
<color>ff0000ff</color>
<width>4</width>
</LineStyle>
</Style>
<MultiGeometry>
<LineString>
<tessellate>1</tessellate>
<coordinates>
138.968309,35.716577,17.0
138.967998,35.716859,17.0
138.967526,35.717252,20.0
138.967055,35.717494,20.0
</coordinates>
</LineString>
</MultiGeometry>
</Placemark>
</Document>
</kml>
Save this as a .kml and it will open in Google Earth
KML is just XML. I'd suggest you create something like what you're looking for using Google Earth. Save it as KML and open it with a text editor to get an idea of what you need to output.
You can generate XML using libxml2 or KissXML
Related
I have a KML file with all the countries and polygons. I am trying to create an app that get a Lat & Lon and detecting in which country belongs using this KML. I tried SimpleKML and KMLViewer with no luck.
The kml structure is:
<Document>
<Folder>
<Folder>
<name>A -</name>
<Placemark>
<name>Afghanistan</name>
<description></description>
<Style>
<PolyStyle>
<color>aaffffff</color>
<colorMode>random</colorMode>
</PolyStyle>
</Style>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
65.62729644775391,37.33319854736328,0 65.64692687988283,37.45888137817383,0
...
...
coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>Albania</name>
..
..
..
1) It would be better to use xml parser and save the data on a local database?
2)Is there any function to determine in which polygonal is the given lat/lon ?
Thank you
The parsing should be pretty easy using NSXMLParser, look for names and associate them with coordinates. The more interesting part is to test the polygons for inclusion of a point.
Here's a highly regarded SO article, that looks like it borrows somewhat from this wikipedia article. What you would do is build a collection of polygons, and enumerate them testing each for the inclusion of some given coordinates.
The other thing to think about is to skip the parsing and polygon testing altogether and use the google geocoding api. This section talks specifically about getting address info (including country) from a latitude and longitude.
What's the best way to retrieve an array containing the file names of the files used to load a certain CCTMXTiledMap ? I need to get the tileset file names because I want to dispose of them personally from the Cache in a future.
According to the documentation and declaration of CCTMXTiledMap, you'll want to walk the property NSMutableArray* objectGroups. Otherwise, you'll need to maintain your own data structure.
This thread contains robust documentation and examples that should help you.
Open the tmx file, it is an xml file, and search for
it has a tag with a source attribute.
<tileset firstgid="1" name="sewer_tileset" tilewidth="24"
tileheight="24"> <image source="sewer_tileset.png" trans="ff00ff"
width="192" height="217"/> </tileset>
you can parse the xml and just find all tileset->images.
You will need an xml parser if you want to do it on the phone, here is a good tutorial on that :http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
i have an xml file like this.
<?xml version="1.0" encoding="UTF-8"?>
<imageset>
<category>
<image>SQUIRREL</image>
<image>FOX</image>
<image>TIGER</image>
<image>LION</image>
</category>
</imageset>
Now i need to add another elemnt to the parent node imageset like this.
eg: i need to add <image>DOG</image>
SQUIRREL
FOX
TIGER
LION
DOG
i know that to get elements by node wise we need to use xml parse.
But i don't know to write element to the same xml file.
How can i done can any one please help me.
Thank u in advance.
If you are on iPhone you can use either a SAX parser called The "NSXMLParser" class
or you can use a DOM parser Like NSXML for this one You want to use DOM Like NSXML since you want to edit the file. On iPhone they Took NSXMLDocument out due to it being too resource intensive. Use something like either "Kiss XML" or "Touch Base XML".
If you are not familier with parsing XML its really simple and easy I suggest since you are on the iPhone use the ADC Documentation here:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NSXML_Concepts/NSXML.html
Its a great tutorial!
Hello i want to parse xml.Please help me.Here is my node
<RadioButton id="1" name="Gender">
<Item>Male</Item>
<Item>Female</Item>
</RadioButton>
i want to parse and i want to create comma separated string
Here are releated the SO post,
Parser XML with NSXMLParser
http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
NSXMLParser example
below is the blog tutorial for using NSXMLParser.
http://markstruzinski.com/?p=47
http://sivatechranti.wordpress.com/2010/03/05/parsing-xml-on-iphone/
easy to explain
anonter site very useful
http://mac.softpedia.com/progDownload/TouchXML-Download-47225.html
direct download...and see this project and implemant in yr project and drag in your project and use directly.....
i want to parse the xml File. xml File structure is following
<?xml version="1.0" encoding="utf-8"?>
<Level>
<p id='327'>
<Item>
<Id>5877</Id>
<Type>0</Type>
<Icon>---</Icon>
<Title>Btn1Item1</Title>
</Item>
<Item>
<Id>5925</Id>
<Type>0</Type>
<Icon>---</Icon>
<Title>Btn1Item4</Title>
</Item>
</p>
<p id='328'>
<Item>
<Id>5878</Id>
<Type>0</Type>
<Icon>---</Icon>
<Title>Btn2Item1</Title>
</Item>
<Item>
<Id>5926</Id>
<Type>0</Type>
<Icon>---</Icon>
<Title>Btn2Item4</Title>
</Item>
</p>
</Level>
in above code there are only 2 tag for <p>. but in actual there are multiple tag. i want to search the specific tag for which attribute id have some specific value (say 327).
so one way is that i parse the XML file from start to get the desired result. whether there are any other method from which i can direct locate the desired tag. for example if i want to search the <p> tag in above XML for attribute id =328, then it does not parse the id=327 and direct return only those item which are related to id=328
Please suggest
Depends how you define "parse".
A "quick & dirty" (and potentially buggy) way would be to find the fragment using a regex search (or a custom parser) first, then feed the fragment to a true XML parser. I don't know of anything that would do this for you, you'd have to roll it yourself. I would suggest that it's not the way to go.
The next level is to feed it through a SAX-like parser (which NSXMLParser is a form of).
In your handler for the <p> element, check the id attribute and if it matches your value (or values), set a flag to indicate if child elements should be interpreted.
In your child element handlers, just check that flag first (in a raw NSXMLParser handler all elements would go to the same method, of course).
So it's true that NSXMLParser would be parsing the whole document - but just to do the minimal work to establish the correct XML parser context. The real work of handling the elements would be deferred until the value is met. I don't see any way around that without something hacky like the regex suggestion.
If this is too much overhead I'd reconsider whether XML is the right serialization format for you (assuming you have any control over that)?
If you do stick with NSXMLParser, my blog article here might help to at least make the experience nicer.
The libxml2 library can receive XPath queries with the following extensions. With these extensions you might issue the XPath query /p[#id = "328"] to retrieve that specific node's children.