Search code examples
javaandroidgoogle-maps-api-3

Nearby Place is not being shown


I'm making a Find nearby vape store App. But when I click find vape store, the map won't show the place. Below is the code:-

btnFind.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
           StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
            sb.append("&key=" + API_KEY_SERVER);
            sb.append("location=" + mLatitude + "," + mLongitude);
            sb.append("&radius=10000");
            sb.append("&keyword=Vape");
            sb.append("&sensor=true");
            Toast.makeText(MapsActivity.this,
                    "Your Message", Toast.LENGTH_LONG).show();

            new PlacesTask().execute(sb.toString());
        }

Solution

  • It appears as if you have perhaps missed an & in the construction of the paramerters. The location parameter is not prepended by an ampersand. Try this:

    public void onClick(View v) {
        StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
        sb.append("&key=" + API_KEY_SERVER);
        sb.append("&location=" + mLatitude + "," + mLongitude);
        sb.append("&radius=10000");
        sb.append("&keyword=Vape");
        sb.append("&sensor=true");
        Toast.makeText(MapsActivity.this,"Your Message", Toast.LENGTH_LONG).show();
    
        new PlacesTask().execute(sb.toString());
    }
    

    Also note that the sensor parameter is no longer required.