在Android Studio中使用Google Places API时,无法找到汽车维修车库汽车店。

问题描述 投票:1回答:1
    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个回答
0
投票

你需要搜索类型为 car_repair. 这里是 Place Search查询支持的类型列表。所以,例如,你可以做这样的事情。

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;

希望能帮到你

© www.soinside.com 2019 - 2024. All rights reserved.