【发布时间】:2017-04-20 09:43:57
【问题描述】:
我已经生成了Current location 值,我正在动态地将它传递给 URL。我在我的 Logcat 中获得了 Latitude 和“经度”的值。但当前未生成LatLongUrl 的动态网址。
Log.d(String.valueOf(mLastLocation.getLatitude()),"Latitude");
Log.d(String.valueOf(mLastLocation.getLongitude()),"Longitude");
//urlJsonObj = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=21.2150756,72.8880545&radius=500&type=hospital&key=AIzaSyBldIefF25dfjjtMZq1hjUxrj4T4hK66Mg";
urlJsonObj = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+String.valueOf(mLastLocation.getLatitude()+","+String.valueOf(mLastLocation.getLongitude()+"&radius=500&type=hospital&key=AIzaSyBldIefF25dfjjtMZq1hjUxrj4T4hK66Mg";
Log.d(urlJsonObj,"LatLongUrl");
Logcat 显示如下,其中生成了纬度和“经度”值,但当前未生成 LatLongUrl 的动态 URl。
04-20 15:00:45.477 3209-3209/com.example.chaitanya.nearbyplace D/21.225225225225223: Latitude
04-20 15:00:45.477 3209-3209/com.example.chaitanya.nearbyplace D/72.8905100797212: Longitude
[ 04-20 15:00:45.477 3209: 3209 D/https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=21.225225225225223&radLatLongUrl
更新问题
我有如下更新代码。但它仍然没有正确生成 URL。
String Latitude = String.valueOf(mLastLocation.getLatitude());
String Longitude = String.valueOf(mLastLocation.getLongitude());
urlJsonObj = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+Latitude+","+Longitude+"&radius=500&type="+TypeName+"&key=AIzaSyBldIefF25dfjjtMZq1hjUxrj4T4hK66Mg";
Log.d(urlJsonObj,"LatLongUrl");
在 Logcat 中
[ 04-20 15:24:57.826 23415:23415 D/https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=21.225225225225223,72.LatLongUrl
【问题讨论】:
-
声明String.valueOf(mLastLocation.getLatitude())和String.valueOf(mLastLocation.getLongitude()并使用String格式生成URL。
-
首先在你的 lJsonObject 中设置硬编码的位置值并检查它是否即将到来!
-
我也这样做过。但它仍然会生成代理 URL。 @Sajithv
-
由于您要连接字符串,因此您不必显式地执行
String.valueOf()。使用URL.parse()。相应地添加括号。 -
更新 URL 后的日志是什么