【问题标题】:Can't find Car-repair/garage/motor shops while using Google Places API in Android Studio在 Android Studio 中使用 Google Places API 时找不到汽车修理店/车库/汽车店
【发布时间】:2020-08-27 06:42:42
【问题描述】:
    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;


是否有特定的关键字要搜索?因为我可以找到附近的医院、餐馆但找不到任何汽车维修店。代码中有什么要添加的吗?

提前致谢。

【问题讨论】:

    标签: java android android-studio google-maps google-places-api


    【解决方案1】:

    您需要搜索car_repair 类型的地点。 Here's 地点搜索查询支持的类型列表。所以例如你可以这样做:

    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;
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2020-01-26
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 2019-12-25
      • 2018-01-12
      相关资源
      最近更新 更多