-1

I have generated Current location value and i am passing it to the URL dynamically. I am getting value of Latitude and 'Longitude' in my Logcat. but dynamic URl for LatLongUrl is not generated currently.

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 displaying as bellow in which value of Latitude and 'Longitude' generated but dynamic URl for LatLongUrl is not generated currently.

    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

Updated quetion

i have update code as bellow. but its still not generateed URL properly.

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

in Logcat

     [ 04-20 15:24:57.826 23415:23415 D/https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=21.225225225225223,72.LatLongUrl
alka vaghela
  • 805
  • 4
  • 13
  • 33

3 Answers3

1

Replace your line with this

 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";
bhaumiksoni
  • 244
  • 1
  • 7
0

I think your Parenthesis after String.valueOf(mLastLocation.getLatitude()) and String.valueOf(mLastLocation.getLongitude()) is missing

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

That's in your log

[ 04-20 15:00:45.477 3209: 3209 D/https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=21.225225225225223&radLatLongUrl

it's like this

Mukeshkumar S
  • 785
  • 1
  • 14
  • 30
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);

This will helps you to resolve problem.

Sajith Vijesekara
  • 1,324
  • 2
  • 17
  • 52