在 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;

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

提前谢谢。

您需要搜索类型为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;

希望这有帮助!

相关内容

  • 没有找到相关文章

最新更新