使用 USGS 高程查询服务获取高程(地面高度)API
Get elevation (altitude at ground level) using USGS Elevation Query Service API
我花了一周的大部分时间试图研究如何通过我的 android 应用程序连接到 USGS 高程查询服务 API,但结果令人尴尬。我发现的最好的是 6 年前 here 使用现在已弃用的代码。剧透 - 我无法让它工作。
使用 GPS 进行海拔高度对于我的应用程序需求来说太不可靠了,即使在对数据应用了广泛的移动平均线和 low/high 通过过滤之后也是如此。
任何人都可以分享他们的 recommendations/code 以通过 USGS 海拔查询服务检索海拔。我当然可以提供纬度和经度?
您只需将已弃用的 httpClient 替换为 Google 推荐的 HttpUrlConnection,即可使用您引用的那个。那里有很多教程,包括 Google's own sample code explained here.
对 "USGS Elevation Query Service API" 的简单 google 搜索指向 http://ned.usgs.gov/epqs/(与您链接的问题不同的地址。API 看起来非常简单。
下面是一个呼叫拉斯维加斯的例子 http://nationalmap.gov/epqs/pqs.php?x=36.1251958&y=-115.3150863&output=json&units=Meters
问题是,根据他们的网站 "If unable to find data at the requested point, this service returns -1000000",我个人找不到任何他们有位置的位置(试过拉斯维加斯和旧金山)。
或者,Google 有海拔 API,考虑到 Google 地图,我只能假设它非常好。在这里你可以看到文档 https://developers.google.com/maps/documentation/elevation/start and here is an example query https://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034
对于实际调用本身,建议使用 OkHttp (http://square.github.io/okhttp/) 或 Retrofit(使用 OkHttp)为您做线程),但基本代码是:
OkHttpClient client = new OkHttpClient();
String getElevation(String url) throws IOException {
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
然后它只是解析 Json 字符串
我只是在寻找相关内容时发现了此页面,并注意到第一个响应中存在错误。它是这样说的:
Here is an example call to Las Vegas
http://nationalmap.gov/epqs/pqs.php?x=36.1251958&y=-115.3150863&output=json&units=Meters
The problem is that as per their website "If unable to find data at
the requested point, this service returns -1000000" and I personally
couldn't find any location that they have location (tried Las Vegas
and San Francisco).
示例中 X 和 Y 颠倒了。切换到
https://nationalmap.gov/epqs/pqs.php?y=36.1251958&x=-115.3150863&output=json&units=Meters
而且效果很好。希望这对未来的搜索者有所帮助!
我花了一周的大部分时间试图研究如何通过我的 android 应用程序连接到 USGS 高程查询服务 API,但结果令人尴尬。我发现的最好的是 6 年前 here 使用现在已弃用的代码。剧透 - 我无法让它工作。
使用 GPS 进行海拔高度对于我的应用程序需求来说太不可靠了,即使在对数据应用了广泛的移动平均线和 low/high 通过过滤之后也是如此。
任何人都可以分享他们的 recommendations/code 以通过 USGS 海拔查询服务检索海拔。我当然可以提供纬度和经度?
您只需将已弃用的 httpClient 替换为 Google 推荐的 HttpUrlConnection,即可使用您引用的那个。那里有很多教程,包括 Google's own sample code explained here.
对 "USGS Elevation Query Service API" 的简单 google 搜索指向 http://ned.usgs.gov/epqs/(与您链接的问题不同的地址。API 看起来非常简单。
下面是一个呼叫拉斯维加斯的例子 http://nationalmap.gov/epqs/pqs.php?x=36.1251958&y=-115.3150863&output=json&units=Meters
问题是,根据他们的网站 "If unable to find data at the requested point, this service returns -1000000",我个人找不到任何他们有位置的位置(试过拉斯维加斯和旧金山)。
或者,Google 有海拔 API,考虑到 Google 地图,我只能假设它非常好。在这里你可以看到文档 https://developers.google.com/maps/documentation/elevation/start and here is an example query https://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034
对于实际调用本身,建议使用 OkHttp (http://square.github.io/okhttp/) 或 Retrofit(使用 OkHttp)为您做线程),但基本代码是:
OkHttpClient client = new OkHttpClient();
String getElevation(String url) throws IOException {
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
然后它只是解析 Json 字符串
我只是在寻找相关内容时发现了此页面,并注意到第一个响应中存在错误。它是这样说的:
Here is an example call to Las Vegas http://nationalmap.gov/epqs/pqs.php?x=36.1251958&y=-115.3150863&output=json&units=Meters
The problem is that as per their website "If unable to find data at the requested point, this service returns -1000000" and I personally couldn't find any location that they have location (tried Las Vegas and San Francisco).
示例中 X 和 Y 颠倒了。切换到
https://nationalmap.gov/epqs/pqs.php?y=36.1251958&x=-115.3150863&output=json&units=Meters
而且效果很好。希望这对未来的搜索者有所帮助!