【问题标题】:Retrieve places by type from android maps api从 android maps api 按类型检索地点
【发布时间】:2017-03-19 16:10:13
【问题描述】:

我正在使用来自 android maps api 的 Geocoder 来检索 android studio 中的位置。它正在工作,但不是我想要的。我想按位置地址搜索并选择类型并从该地址和所选类型中获取所有匹配结果。

String searchString = "London";
Geocoder gc = new Geocoder(this);
List<Address> list = gc.getFromLocationName(searchString, 10);
if (list.size() > 0) {
    Address add = list.get(0);
    String locality = add.getLocality();
    Toast.makeText(this, "Found: " + locality, Toast.LENGTH_SHORT).show();
}

我可以改为以伦敦为例,然后选择“体育场”之类的位置类型,然后从伦敦获取所有体育场吗?

我尝试了另一种解决方案,但不确定是否可以将其实现到 Android,即检索 JSON 的 googleapis:

http://maps.googleapis.com/maps/api/geocode/json?address=stadium+Near+London=true

它给了我正确的答案,但只有一个结果, 我在这里有两个问题: 1.如何获得所有比赛场馆? 2. 我可以在安卓应用中实现吗?喜欢从应用中读取检索到的 json 数据?

【问题讨论】:

    标签: android json google-maps geolocation


    【解决方案1】:

    我认为您实际上应该使用适用于 Android 的 Places API 而不是地理编码器。地理编码 API 并不是真的用于返回某种类型的多个结果,但地方 API 是。请在此处查看有关以编程方式获取位置预测的文章:

    https://developers.google.com/places/android-api/autocomplete#get_place_predictions_programmatically

    这将允许您将结果偏向某个区域,例如伦敦。并允许您返回某种类型的结果,例如体育场。虽然这可能不是您正在寻找的东西,但我相信这是 Google 提供的最接近的东西。您可能还想在此处查看 Places API for Android 可以执行的其他操作:

    https://developers.google.com/places/android-api/start

    我希望这会有所帮助!

    【讨论】:

    • 感谢您的帮助,但不幸的是 android places api 并没有那么有用。它在请求值的数量方面施加了很多限制。我确实将 place api 用于 Web 应用程序。它通过 json 返回值,并且似乎是迄今为止最有用的一个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多