我已生成Current location
值,我正在动态地将其传递给URL。我在Logcat中获得Latitude
和'经度'的价值。但目前尚未生成LatLongUrl
的动态URl。
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显示如下:生成Latitude和'Longitude'的值但当前未生成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
答案 0 :(得分:1)
用此
替换你的行 String urlJsonObj =
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" +
new BigDecimal(mLastLocation.getLatitude()).toString() + "," +
new BigDecimal(mLastLocation.getLongitude()).toString() +
"&radius=500&type=hospital&key=AIzaSyBldIefF25dfjjtMZq1hjUxrj4T4hK66Mg";
答案 1 :(得分:0)
我认为在String.valueOf(mLastLocation.getLatitude())和String.valueOf(mLastLocation.getLongitude())之后你的括号 缺少
String 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";
那是你的日志
[04-20 15:00:45.477 3209:3209 D / https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=21.225225225225223&radLatLongUrl
就像这样
答案 2 :(得分:0)
String latitude = String.valueOf(mLastLocation.getLatitude());
String longitude = String.valueOf(mLastLocation.getLongitude())
String urlJsonObj =String.format("https://maps.googleapis.com/maps/api/place/nearbysearch/json?" +
"location=%s,%s &radius=500&type=hospital&key=AIzaSyBldIefF25dfjjtMZq1hjUxrj4T4hK66Mg",latitude,longitude);
这有助于您解决问题。