从我的谷歌地图android导出KML文件
我在谷歌地图上画了一些线和多边形,我想把这张地图导出为kml文件,我该怎么做 要将kml加载到Android上的Google Maps中而无需编写应用程序,您可以在某个地方创建一个带有kml文件地理uri链接的小html文件,然后在任何Android web浏览器中单击该链接 例如:假设您的kml文件位于/sdcard/overlay.kml中,然后编写一个geo uri链接,如下所示:从我的谷歌地图android导出KML文件,android,kml,Android,Kml,我在谷歌地图上画了一些线和多边形,我想把这张地图导出为kml文件,我该怎么做 要将kml加载到Android上的Google Maps中而无需编写应用程序,您可以在某个地方创建一个带有kml文件地理uri链接的小html文件,然后在任何Android web浏览器中单击该链接 例如:假设您的kml文件位于/sdcard/overlay.kml中,然后编写一个geo uri链接,如下所示: <html> <head><title>Example KML link
<html>
<head><title>Example KML link page using a geo-uri</title></head>
<body>
<a href="geo:0,0?q=file:///sdcard/overlay.kml">overlay.kml</a>
</body>
</html>
使用地理uri的KML链接页面示例
单击链接将启动“地图”,然后“地图”将尝试加载并删除您的kml
(显然,如果您的kml文件位于web服务器上,则可以用http://servername替换文件://part)
但是,请注意,Android版的地图似乎无法处理与桌面版(或桌面谷歌地球)相同版本/范围的kml元素。在解析kml时,我将所有内容都放在一个类中。我在第二个应用中使用了我第一个应用中的同一类。只是扩展了原来的类。对我来说,100%重用来自另一个应用程序的类并使用超级操作码是非常酷的 无论如何。基本上,它是一个多段线选项列表和一个标记选项列表 super.get_po是多段线选项 super.get_mo哪一个是标记选项 然后,在编写kml时,我只是将该类序列化回来。我的高尔夫应用程序取决于标记和线条的顺序。对于每个孔,它使用标记、线、标记和我使用的样式与每个元素具有自己样式的样式相同 从中下载了两部惊天动地的电影,我可能还有我妻子的手机
@Override
public void saveGolfMap() {
// TODO Auto-generated method stub
FileOutputStream fileos = null;
StringBuilder sb = new StringBuilder();
try {
fileos = new FileOutputStream(super.get_pathstring());
} catch (FileNotFoundException e) {
// Log.e("FileNotFoundException", e.toString());
e.printStackTrace();
}
// serialize the file();
try {
xmlSerializer = XmlPullParserFactory.newInstance().newSerializer();
} catch (XmlPullParserException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
xmlSerializer.setOutput(fileos, "UTF-8");
xmlSerializer.startDocument(null, null);
xmlSerializer.setFeature(
"http://xmlpull.org/v1/doc/features.html#indent-output",
true);
xmlSerializer.startTag(null, "kml");
xmlSerializer.attribute(null, "xmlns",
"http://earth.google.com/kml/2.2");
xmlSerializer.startTag(null, "Document");
xmlSerializer.startTag(null, "name");
xmlSerializer.text("todo put the name here");
xmlSerializer.endTag(null, "name");
xmlSerializer.startTag(null, "description");
xmlSerializer.cdsect("todo put the description here");
xmlSerializer.endTag(null, "description");
// spin through the marker options and create a style section for
// each two
// markers create three style sections
// <Style id="style1">
// <IconStyle>
// <Icon>
// <href>http://maps.gstatic.com/mapfiles/ms2/micons/golfer.png</href>
// </Icon>
// </IconStyle>
// </Style>
// <Style id="style2">
// <IconStyle>
// <Icon>
// <href>http://maps.gstatic.com/mapfiles/ms2/micons/flag.png</href>
// </Icon>
// </IconStyle>
// </Style>
// <Style id="style3">
// <LineStyle>
// <color>73FF0000</color>
// <width>3</width>
// </LineStyle>
// </Style>
setInt();
int y = 0;
for (int k = 0; k < mosize; k++) {
y += 1;
if (k % 2 == 0) {
// write out the tee marker style
xmlSerializer.startTag(null, "Style");
xmlSerializer.attribute(null, "id",
"style" + Integer.toString(y));
xmlSerializer.startTag(null, "IconStyle");
xmlSerializer.startTag(null, "Icon");
xmlSerializer.startTag(null, "href");
xmlSerializer
.text("http://maps.gstatic.com/mapfiles/ms2/micons/golfer.png");
xmlSerializer.endTag(null, "href");
xmlSerializer.endTag(null, "Icon");
xmlSerializer.endTag(null, "IconStyle");
xmlSerializer.endTag(null, "Style");
// write out the polyline style
y += 1;
xmlSerializer.startTag(null, "Style");
xmlSerializer.attribute(null, "id",
"style" + Integer.toString(y));
xmlSerializer.startTag(null, "LineStyle");
xmlSerializer.startTag(null, "color");
xmlSerializer.text("73FF0000");
xmlSerializer.endTag(null, "color");
xmlSerializer.startTag(null, "width");
xmlSerializer.text("10");
xmlSerializer.endTag(null, "width");
xmlSerializer.endTag(null, "LineStyle");
xmlSerializer.endTag(null, "Style");
} else {
// write out the cup marker style
xmlSerializer.startTag(null, "Style");
xmlSerializer.attribute(null, "id",
"style" + Integer.toString(y));
xmlSerializer.startTag(null, "IconStyle");
xmlSerializer.startTag(null, "Icon");
xmlSerializer.startTag(null, "href");
xmlSerializer
.text("http://maps.gstatic.com/mapfiles/ms2/micons/flag.png");
xmlSerializer.endTag(null, "href");
xmlSerializer.endTag(null, "Icon");
xmlSerializer.endTag(null, "IconStyle");
xmlSerializer.endTag(null, "Style");
}
}
// write placemark for tee
// write poly lines
// write placemark for cup
// <Placemark>
// <name>Tee Hole 1</name>
// <description><![CDATA[]]></description>
// <styleUrl>#style1</styleUrl>
// <Point>
// <coordinates>-xx.999999,xx.999999,0.000000</coordinates>
// </Point>
// </Placemark>
y = 0;
for (int k = 0; k < mosize; k++) {
y += 1;
// write out the tee or cup PlaceMark
mo = super.get_mo().get(k);
xmlSerializer.startTag(null, "Placemark");
xmlSerializer.startTag(null, "name");
xmlSerializer.text(mo.getTitle());
xmlSerializer.endTag(null, "name");
xmlSerializer.startTag(null, "description");
xmlSerializer.cdsect("");
xmlSerializer.endTag(null, "description");
xmlSerializer.startTag(null, "styleUrl");
xmlSerializer.text("#style" + Integer.toString(y));
xmlSerializer.endTag(null, "styleUrl");
xmlSerializer.startTag(null, "Point");
xmlSerializer.startTag(null, "coordinates");
ll = mo.getPosition();
xmlSerializer.text(Double.toString(ll.longitude) + ","
+ Double.toString(ll.latitude) + ",0.000000");
xmlSerializer.endTag(null, "coordinates");
xmlSerializer.endTag(null, "Point");
xmlSerializer.endTag(null, "Placemark");
// write out the polyline options
// <Placemark>
// <name>Hole One</name>
// <description><![CDATA[]]></description>
// <styleUrl>#style3</styleUrl>
// <LineString>
// <tessellate>1</tessellate>
// <coordinates>
// -xx.999999,xx.999999,0.000000
// -xx.999999,xx.999999,0.000000
// -xx.999999,xx.999999,0.000000
// -xx.9999999,xx.999999,0.000000
// -xx.9999999,xx.999999,0.000000
// </coordinates>
// </LineString>
// </Placemark>if (hole > 0){
if (k % 2 == 0) {
int z = k / 2;
if (z < posize) {
y += 1;
po = this.get_po().get(z);
xmlSerializer.startTag(null, "Placemark");
xmlSerializer.startTag(null, "name");
xmlSerializer.endTag(null, "name");
xmlSerializer.startTag(null, "description");
xmlSerializer.cdsect("");
xmlSerializer.endTag(null, "description");
xmlSerializer.startTag(null, "styleUrl");
xmlSerializer.text("#style" + Integer.toString(y));
xmlSerializer.endTag(null, "styleUrl");
xmlSerializer.startTag(null, "LineString");
xmlSerializer.startTag(null, "tessellate");
xmlSerializer.text("1");
xmlSerializer.endTag(null, "tessellate");
xmlSerializer.startTag(null, "coordinates");
sb.setLength(0);
for (LatLng ll3 : po.getPoints()) {
sb.append(Double.toString(ll3.longitude));
sb.append(",");
sb.append(Double.toString(ll3.latitude));
sb.append(",0.000000\n");
}
sb.setLength(sb.length() - 2);
String s = sb.toString();
xmlSerializer.text(s);
xmlSerializer.endTag(null, "coordinates");
xmlSerializer.endTag(null, "LineString");
xmlSerializer.endTag(null, "Placemark");
}
}
}
xmlSerializer.endTag(null, "Document");
xmlSerializer.endTag(null, "kml");
xmlSerializer.endDocument();
xmlSerializer.flush();
fileos.close();
} catch (Exception e) {
e.printStackTrace();
// Log.e("Exception", "Exception occured in wroting");
}
}
@覆盖
公共void saveGolfMap(){
//TODO自动生成的方法存根
FileOutputStream fileos=null;
StringBuilder sb=新的StringBuilder();
试一试{
fileos=newfileoutputstream(super.get_pathstring());
}catch(filenotfounde异常){
//e(“FileNotFoundException”,e.toString());
e、 printStackTrace();
}
//序列化文件();
试一试{
xmlSerializer=XmlPullParserFactory.newInstance().newSerializer();
}捕获(XmlPullParserException e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
试一试{
setOutput(fileos,“UTF-8”);
startDocument(null,null);
xmlSerializer.setFeature(
"http://xmlpull.org/v1/doc/features.html#indent-输出“,
正确的);
startTag(null,“kml”);
属性(null,“xmlns”,
"http://earth.google.com/kml/2.2");
startTag(null,“文档”);
startTag(null,“name”);
text(“todo将名称放在这里”);
endTag(null,“name”);
startTag(null,“description”);
cdsect(“todo将描述放在这里”);
endTag(null,“description”);
//旋转标记选项并为其创建样式部分
//每两个
//标记创建三个样式部分
//
//
//
// http://maps.gstatic.com/mapfiles/ms2/micons/golfer.png
//
//
//
//
//
//
// http://maps.gstatic.com/mapfiles/ms2/micons/flag.png
//
//
//
//
//
//73FF0000
// 3
//
//
setInt();
int y=0;
对于(int k=0;k