在这里发布与错误相关的代码和日志,问题是尝试使用 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);