ポイントタイプのKMLファイルを読み込んで、Google Elevation APIを使用して標高を更新するアプリケーションを開発しました。あなたが見ることができるように、それはポイントの緯度と経度を受け取り、APIキーを付けて標高を取得します。私のKMLファイルが複数のポイントを持っているので、私は、ポイントの緯度と長い読みキーでそれを追加し、このようにGoogleの標高API.SomethingにURLを送信するためのThreadPoolを使用しました:アンドロイドスレッドプールの補完コールバック
ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(CORE_NUMBERS + 1);
String providerURL = provider.getServiceURL();
String providerKey = provider.getServiceAPIkey();
for (PointFeature p: points) {
String coordinate = p.getLatitude() + "," + p.getLongitude(); // get latitude and longitude of the feature
String url = providerURL + "locations=" + coordinate + providerKey; // creating the url of web service which contains coordinate
HeightTask task = new HeightTask(url, p); // task of each points
executor.execute(task);
}
heightTaskクラスAPIからのJSON結果を解析して高度を取得し、heithUpdateフラグを設定します。ここでは、スニペットは次のとおりです。
public class HeightTask implements Runnable {
private String url;
private Feature feature;
public HeightTask(String url, Feature f) {
this.feature = f;
this.url = url;
}
@Override
public void run() {
if (feature instanceof PointFeature) {
float height = GoogleAPIJsonParser.parsePoint(HttpManager.getData(url));
if (height != Float.NaN){
feature.updateHeight(height);
feature.setHeightUpdated(true);
Log.d("elevationPoint",height+"");
}
}
}
}
私は必要なものは、層内のすべてのポイントの標高が更新されたかどうかを知るためのコールバックです。 threadPoolにパターンがありますか、またはすべてのポイントをループしてhieghtUpdateフラグをチェックしますか?