未显示附近的地点

时间:2018-12-14 16:51:13

标签: java android google-maps-api-3

我正在制作查找附近的vape商店应用。但是,当我单击“查找vape商店”时,地图将不会显示该地点。下面是代码:-

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());
        }

1 个答案:

答案 0 :(得分:0)

似乎在拟定参数的构造中您可能错过了&location参数的前面没有“&”符号。试试这个:

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());
}

还要注意,不再需要sensor参数。