java - 在 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;
有没有具体的关键词要搜索?因为我可以找到附近的医院,餐馆,但找不到任何汽车维修店。代码中是否有任何要添加的内容。
提前致谢。
解决方案
您需要搜索 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;
希望这可以帮助!
推荐阅读
- java - Java 正则表达式 (java.util.regex)。搜索美元符号
- java - 对于上面提到的程序,我收到一个测试用例的运行时错误。所有剩余的测试用例都通过了。有什么建议么
- reactjs - React (Native) 架构和状态管理
- mysql - 每个连接只能打开和使用一个流式传输结果集。确保您已在任何活动结果上调用 .close()
- javascript - React Native 中的实时位置跟踪与 Expo
- mysql - 如何从两个表中获取数据
- snowflake-cloud-data-platform - 如何在存储过程中使用 Show 命令 - 不工作
- jquery - 尝试使用数据库中的问题和答案创建常见问题解答(MVC Web-Api)
- android - Mapbox NavigationView GPS 跟踪箭头可绘制
- python - 将pcap文件中的所有字段导出到python中的csv