0

在这里发布与错误相关的代码和日志,问题是尝试使用 map api v2 显示位置,同时将数据发送到 url 得到这个异常,所以我认为发送请求有问题,但我得到了这样的 JSON 数据对我有帮助。

    10-03 19:45:41.422: W/System.err(27832): java.lang.IllegalArgumentException: Illegal character in query at index 128: https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=21.21544712,81.32074942&radius=1000&sensor=true&types=food|bar|club&key=something
10-03 19:45:41.422: W/System.err(27832):    at java.net.URI.create(URI.java:727)
10-03 19:45:41.422: W/System.err(27832):    at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
10-03 19:45:41.422: W/System.err(27832):    at com.tukutane.StartActivity$GetPlaces.doInBackground(StartActivity.java:220)
10-03 19:45:41.422: W/System.err(27832):    at com.tukutane.StartActivity$GetPlaces.doInBackground(StartActivity.java:1)
10-03 19:45:41.422: W/System.err(27832):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-03 19:45:41.422: W/System.err(27832):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-03 19:45:41.422: W/System.err(27832):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-03 19:45:41.432: W/System.err(27832):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-03 19:45:41.432: W/System.err(27832):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-03 19:45:41.432: W/System.err(27832):    at java.lang.Thread.run(Thread.java:856)

代码:

    // build places query string
                    String placesSearchStr = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
                            + "location="
                            + mCurrentLocation.getLatitude()
                            + ","
                            + mCurrentLocation.getLongitude()
                            + "&radius=1000&sensor=true"
                            + "&types=food|bar|club"
                            + "&key=xxxxxxxx";
                    // execute query
                    new GetPlaces().execute(placesSearchStr);
        // Move the camera instantly to User location with a zoom of 12.
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
                USER_LOCATION, 12));

        // Zoom in, animating the camera.
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
4

1 回答 1

2

索引 128 处查询中的非法字符:...

这意味着您的字符串中有非法字符。在您的情况下,它是一个管道(|)。您需要将字符编码为%7C. 如果您访问您发布的链接,您也可以看到它在那里的显示方式。

您可以手动执行此操作,也可以使用URLEncoder

+ "&types=food%7Cbar%7Cclub"

或者

+ "&types=" + URLEncoder.encode("food|bar|club", "utf-8")
于 2013-10-03T19:56:08.950 回答