gpt4 book ai didi

android - Ekito 简单 KML 阅读源

转载 作者:太空宇宙 更新时间:2023-11-03 11:08:52 24 4
gpt4 key购买 nike

我在这个链接上有一个 KML: http://myurl.com/mykml.kml

我想从中获取 com.ekito.simpleKML.model KML 对象。我正在尝试这样做:

String url = "http://myurl.com/mykml.kml";
Serializer kmlSerializer = new Serializer();
Kml kml = kmlSerializer.read(url);

但是 kml 对象仍然是 null。

这是 Ekito 简单 KML 库的链接:https://github.com/Ekito/Simple-KML

最佳答案

我看到 Ekito 他无法读取互联网上的文件。测试这个例子!

     private ProgressDialog progressBar;
public static final int KML_PROGRESS = 0;
public String fileURL ="http://myurl.com/mykml.kml";


// set in OnClick Button
new DownloadKML().execute(fileURL);

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case KML_PROGRESS:
progressBar = new ProgressDialog(this);
progressBar.setMessage("Downloading file…");
progressBar.setIndeterminate(false);
progressBar.setMax(100);
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setCancelable(true);
progressBar.show();
return progressBar;
default:
return null;
}
}




class DownloadKML extends AsyncTask<String, String, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(KML_PROGRESS);
}

@Override
protected String doInBackground(String... url) {
int count;

try {

URL url = new URL( url[0] );
URLConnection connect = url.openConnection();
connect.connect();
int progressOfFile = connect.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/KML_Samples.kml");

byte data[] = new byte[1024];

long total = 0;

while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+(int)((total*100)/progressOfFile) );
output.write(data, 0, count);
}

output.flush();
output.close();
input.close();
} catch (Exception e) {}
return null;

}
protected void onProgressUpdate(String... progress) {
progressBar.setProgress(Integer.parseInt(progress[0]));
}

@Override
protected void onPostExecute(String unused) {
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
String pathKML = Environment.getExternalStorageDirectory().toString() + "/KML_Samples.kml";

// load
Serializer kmlSerializer = new Serializer();
Kml kml = kmlSerializer.read(url);
}
}

关于android - Ekito 简单 KML 阅读源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29670865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com