当前未为纬度和经度生成动态 url android

Dynamic url not generated currently for lat and Long android

我已经生成了 Current location 值,我正在将它动态传递给 URL。我在 Logcat 中得到 Latitude 和 'Longitude' 的值。但当前未生成 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

我认为你在 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

是这样的

用这个替换你的行

 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";
 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);

这将帮助您解决问题。