Created
July 23, 2012 10:34
-
-
Save RobGThai/3163006 to your computer and use it in GitHub Desktop.
Snippet code for parsing KML file from Google Maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retrieve navigation data set from either remote URL or String | |
* @param url | |
* @return navigation set | |
*/ | |
public static NavigationDataSet GetNavigationDataSet(String url) { | |
NavigationDataSet navigationDataSet = null; | |
try | |
{ | |
if(LOG_LEVEL <= Log.DEBUG)Log.d(TAG, "url[" + url + "]"); | |
final URL aUrl = new URL(url); | |
if(LOG_LEVEL <= Log.DEBUG)Log.d(TAG, "Connecting..."); | |
final URLConnection conn = aUrl.openConnection(); | |
// conn.setReadTimeout(15 * 1000); // timeout for reading the google maps data: 15 secs | |
conn.connect(); | |
if(LOG_LEVEL <= Log.DEBUG)Log.d(TAG, "Connected..."); | |
/* Get a SAXParser from the SAXPArserFactory. */ | |
SAXParserFactory spf = SAXParserFactory.newInstance(); | |
SAXParser sp = spf.newSAXParser(); | |
/* Get the XMLReader of the SAXParser we created. */ | |
XMLReader xr = sp.getXMLReader(); | |
/* Create a new ContentHandler and apply it to the XML-Reader*/ | |
NavigationSaxHandler navSax2Handler = new NavigationSaxHandler(); | |
xr.setContentHandler(navSax2Handler); | |
if(LOG_LEVEL <= Log.DEBUG)Log.d(TAG, "Parse Stream"); | |
/* Parse the xml-data from our URL. */ | |
xr.parse(new InputSource(aUrl.openStream())); | |
if(LOG_LEVEL <= Log.DEBUG)Log.d(TAG, "Get data frm Parser"); | |
/* Our NavigationSaxHandler now provides the parsed data to us. */ | |
navigationDataSet = navSax2Handler.getParsedData(); | |
} catch (Exception e) { | |
if(LOG_LEVEL <= Log.ERROR)Log.e(TAG, "error getting route info", e); | |
navigationDataSet = null; | |
} | |
return navigationDataSet; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c)2012 Poohdish Rattanavijai | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.robgthai.lib.vo; | |
/** | |
* Class representing placemark used in Google Maps | |
* @author poohdishr | |
* | |
*/ | |
public class Placemark { | |
String title; | |
String description; | |
String coordinates; | |
String address; | |
public String getTitle() { | |
return title; | |
} | |
public void setTitle(String title) { | |
this.title = title; | |
} | |
public String getDescription() { | |
return description; | |
} | |
public void setDescription(String description) { | |
this.description = description; | |
} | |
public String getCoordinates() { | |
return coordinates; | |
} | |
public void setCoordinates(String coordinates) { | |
this.coordinates = coordinates; | |
} | |
public String getAddress() { | |
return address; | |
} | |
public void setAddress(String address) { | |
this.address = address; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment