我使用Google地图为智能手机创建应用,我希望展示从A点到B点的道路。如何做到这一点?
我尝试使用这样的网址:
https://maps.google.com/maps?saddr=50.06469,19.944788&daddr=50.064001,19.92039&dirflg=w&output=kml
但它不起作用(在应用程序中我得到null而不是kml文件)。
Gimer
代码:
try {
/* Create a URL we want to load some xml-data from. */
URL url = new URL("hhttps://maps.google.com/maps?saddr=50.06469,19.944788&daddr=50.064001,19.92039&dirflg=w&output=kml");
/* 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*/
ExampleHandler myExampleHandler = new ExampleHandler();
xr.setContentHandler(myExampleHandler);
/* Parse the xml-data from our URL. */
xr.parse(new InputSource(url.openStream()));
/* Parsing has finished. */
/* Our ExampleHandler now provides the parsed data to us. */
ParsedExampleDataSet parsedExampleDataSet =
myExampleHandler.getParsedData();
/* Set the result to be displayed in our GUI. */
tv.setText(parsedExampleDataSet.toString());
} catch (Exception e) {
/* Display any Error to the GUI. */
tv.setText("Error: " + e.getMessage());
Log.e(MY_DEBUG_TAG, "WeatherQueryError", e);
}
我也试试这个:
final BufferedReader is = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
它适用于kml文件,但当url来自谷歌地图时不是。