How to work with RSS, KML, GoogleMaps and DOM - A simple Webapplication
Let me show you how to use the Content from an RSS Feed including a location. Based on this Location the Feeds will be shown local on Google Earth. There are 3 Steps which are very importand to implement:
- Parsing the location from the Newsfeed
- Getting GPS Data from Google Maps by using the Google Maps API
- Creating a kml file for google earth
As you can see in the screenshot, the location is always shown in the same way. No its not that tricky to parse this unique textpart out of the feed. I did it that way:I used the DOMDocument Object to parse the rss file and to create the kml file.
- First i created the kml file with a DOMDocument Object.
- then i created a second object to parse the feed-xml file to get the desired data.
- in a foreach loop i created the Placemark Tags and the reqired childNodes which are needed to show the feed on google earth
- with the function parseLocation i parsed the Location out of the description-tag of the feed. I used php string methods instead of a regualr expresions but i added also a regex in comment
- to get the geodata i had to create an API Key for maps.google.com
- with this key and the parsed location out of the feed i fetched the latitude and longitude by using the SimpleXMLElement Object in the getGPSData() function
- this function returns an array with the actual lat and lon of the parsed location
- in the main programm this data will be stored in an array as well and outputted in the coordinates-Node of the kml file
- the header function informs the browser that it concerns a kml file
Here you can see the result shown in Google Earth:
