【问题标题】:Illegal character in query to maps.googleapis对 maps.googleapis 的查询中存在非法字符
【发布时间】:2015-10-10 09:09:57
【问题描述】:

我正在开发一个使用 Google 地图的 Android 应用程序。 我找到了用户,我想通过对 maps.googleapis 的查询来显示附近的 POI。 在我的 java 代码中,我有一个与 HttpRequest 一起使用的字符串来获取所有信息。字符串是:

"https://maps.googleapis.com/maps/api/place/nearbysearch/" +
                "json?location="+lat+","+lng+
                "&radius=1000&sensor=true" +
                "&types=food|bar|store|museum|art_gallery"+
                "&key=myKey";

其中 lat 和 lng 是包含用户位置坐标的两个变量,myKey 是我的 API 密钥。 当我在日志部分启动我的应用程序时,我获得“索引 125 处的查询中的非法字符”,因此在地图中我没有获得任何 POI。 但是,如果我删除字符串中的所有 " 和 + 字符并使用浏览器中的链接,我将获得 POI 列表。 我怎样才能在我的应用程序中也获得此列表?我不明白我的字符串中的错误在哪里.. 谢谢大家

【问题讨论】:

  • 我建议您添加一些打印语句,以便您自己更轻松地进行调试。

标签: java android google-maps maps


【解决方案1】:

根据this link'|'字符应替换为 '%7C'

你可以这样使用

String url=""https://maps.googleapis.com/maps/api/place/nearbysearch/" +
                "json?location="+lat+","+lng+
                "&radius=1000&sensor=true" +
                "&types=food|bar|store|museum|art_gallery"+
                "&key=myKey";";
url.replaceAll(" ","%20");

【讨论】:

    猜你喜欢
    • 2013-10-08
    • 2021-03-26
    • 2015-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多