首页 > 解决方案 > 在 Android Studio 中使用 Google Places API 时找不到汽车修理店/车库/汽车店

问题描述

    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            buildGoogleApiClient();
            mMap.setMyLocationEnabled(true);
        }

    }

在这里,我将字符串用作医院,并获得附近的医院

    public void onClick(View v)
    {
        Object dataTransfer[] = new Object[2];
        GetNearbyPlacesData getNearbyPlacesData = new GetNearbyPlacesData();

        switch (v.getId()) {
            case R.id.B_search: {
                EditText tf_location = (EditText) findViewById(R.id.TF_location);
                String location = tf_location.getText().toString();
                List<Address> addressList = null;
                MarkerOptions mo = new MarkerOptions();

                if (!location.equals("")) {
                    Geocoder geocoder = new Geocoder(this);
                    try {
                        addressList = geocoder.getFromLocationName(location, 5);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    for (int i = 0; i < addressList.size(); i++) {
                        Address myAddress = addressList.get(i);
                        LatLng latlng = new LatLng(myAddress.getLatitude(), myAddress.getLongitude());
                        mo.position(latlng);
                        mo.title("Your Search Result");
                        mMap.addMarker(mo);
                        mMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
                    }
                }
            }
            break;
            case R.id.B_hospital:
                mMap.clear();
                String hospital = "hospital";
                String url = getUrl(latitude, longitude, hospital);
                dataTransfer[0] = mMap;
                dataTransfer[1] = url;

                getNearbyPlacesData.execute(dataTransfer);
                Toast.makeText(MapsActivity.this, "Showing Nearby Hospitals", Toast.LENGTH_LONG).show();
                break;


有没有具体的关键词要搜索?因为我可以找到附近的医院,餐馆,但找不到任何汽车维修店。代码中是否有任何要添加的内容。

提前致谢。

标签: javaandroidandroid-studiogoogle-mapsgoogle-places-api

解决方案


您需要搜索 type 的位置car_repair以下是地方搜索查询支持的类型列表。因此,例如,您可以执行以下操作:

case R.id.B_carRepair:
    mMap.clear();
    String carRepair = "car_repair";
    String url = getUrl(latitude, longitude, carRepair);
    dataTransfer[0] = mMap;
    dataTransfer[1] = url;

    getNearbyPlacesData.execute(dataTransfer);
    Toast.makeText(MapsActivity.this, "Showing nearby car repairs", Toast.LENGTH_LONG).show();
    break;

希望这可以帮助!


推荐阅读