Google マップにいくつかの線とポリゴンを描画しました。このマップを kml ファイルとしてエクスポートしたいのですが、どうすればよいですか?
3 に答える
Google マップに線、多角形、円などを描きたい場合は、 www.gmapgis.comを使用してください。このアプリケーションでは、描画を kml ファイルとしてエクスポートできます。
入ってくる kml を解析している間に、すべてをクラスに入れます。この 2 番目のアプリでは、1 番目のアプリと同じクラスを使用します。元のクラスを拡張しただけです。別のアプリのクラスを 100% 再利用し、スーパー オペコードを使用することは、私にとって非常にクールです。
いずれかの方法。基本的には、ポリライン オプションのリストとマーカー オプションのリストです。
ポリライン オプションである super.get_po マーカー オプションである super.get_mo
次に、kml を書いているときにそのクラスをシリアライズします。私のゴルフ アプリは、マーカーとラインの順序に依存しています。穴ごとに、マーカー、ライン、マーカーが続き、各要素に独自のスタイルがあるhttp://maps.google.comと同じスタイルを使用します。
なんと大地を粉砕する私のゴルフアプリから、私とおそらく私の妻の電話を2つダウンロードします。
@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");
}
}
幸運を
アプリを作成せずに Android の Google マップに kml を読み込むには、kml ファイルへの geo-uri リンクを含む小さな html ファイルをどこかに作成し、任意の Android Web ブラウザーでそのリンクをクリックします。
例: kml ファイルが /sdcard/overlay.kml にあると仮定し、次のように geo-uri リンクを記述します。
<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>
リンクをクリックするとマップが起動し、マップは kml を読み込もうとします。
(明らかに、kml ファイルが Web サーバー上にある場合、file:// の部分は http:// サーバー名に置き換えることができます)
ただし、マップの Android バージョンは、デスクトップ バージョン (またはデスクトップ Google Earth) と同じバージョン/範囲の kml 要素を処理していないように見えることに注意してください。