ZERO_RESULTS在检索veterinary_care和pet_store Android Studio的场所类型



我一直在谷歌位置搜索,通常我能很好地得到结果,但最近我只能得到兽医_护理和宠物_商店的ZERO_results,但医院工作得很好。为什么成功回调直接指向我的else语句ZERO_RESULTS?

审查结果医院结果

package com.example.doggeo;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import java.io.IOException;
import java.util.List;
import com.google.android.gms.common.api.GoogleApiClient.*;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,
ConnectionCallbacks,
OnConnectionFailedListener,
LocationListener{

private GoogleMap mMap;
private GoogleApiClient client;
private Marker currentLocationmMarker;
public static final int REQUEST_LOCATION_CODE = 99;
int PROXIMITY_RADIUS = 10000;
double latitude,longitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
checkLocationPermission();
}
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch(requestCode)
{
case REQUEST_LOCATION_CODE:
if(grantResults.length >0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
if(ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) !=  PackageManager.PERMISSION_GRANTED)
{
if(client == null)
{
buildGoogleApiClient();
}
mMap.setMyLocationEnabled(true);
}
}
else
{
Toast.makeText(this,"Permission Denied" , Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}

protected synchronized void buildGoogleApiClient() {
client = new Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
client.connect();
}
@Override
public void onLocationChanged(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
if(currentLocationmMarker != null)
{
currentLocationmMarker.remove();
}
Log.d("lat = ",""+latitude);
LatLng latLng = new LatLng(location.getLatitude() , location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Location");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
currentLocationmMarker = mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomBy(10));
if(client != null)
{
LocationServices.FusedLocationApi.removeLocationUpdates(client,this);
}
}
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 =  findViewById(R.id.TF_location);
String location = tf_location.getText().toString();
List<Address> addressList;

if(!location.equals(""))
{
Geocoder geocoder = new Geocoder(this);
try {
addressList = geocoder.getFromLocationName(location, 5);
if(addressList != null)
{
for(int i = 0;i<addressList.size();i++)
{
LatLng latLng = new LatLng(addressList.get(i).getLatitude() , addressList.get(i).getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(location);
mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(10));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
break;
case R.id.B_hospitals:
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_SHORT).show();
break;

case R.id.B_shops:
mMap.clear();
String pet_store = "pet_store";
url = getUrl(latitude, longitude, pet_store);
dataTransfer[0] = mMap;
dataTransfer[1] = url;
getNearbyPlacesData.execute(dataTransfer);
Toast.makeText(MapsActivity.this, "Showing Nearby Pet Shops", Toast.LENGTH_SHORT).show();
break;
case R.id.B_vet:
mMap.clear();
String Vet = "veterinary_care";
url = getUrl(latitude, longitude, Vet);
dataTransfer[0] = mMap;
dataTransfer[1] = url;
getNearbyPlacesData.execute(dataTransfer);
Toast.makeText(MapsActivity.this, "Showing Nearby Veterinarians", Toast.LENGTH_SHORT).show();
break;
}
}

private String getUrl(double latitude , double longitude , String nearbyPlace)
{
StringBuilder googlePlaceUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
googlePlaceUrl.append("location="+latitude+","+longitude);
googlePlaceUrl.append("&radius="+PROXIMITY_RADIUS);
googlePlaceUrl.append("&type="+nearbyPlace);
googlePlaceUrl.append("&sensor=true");
googlePlaceUrl.append("&key="+"");
Log.d("MapsActivity", "url = "+googlePlaceUrl.toString());
return googlePlaceUrl.toString();
}}

你知道这里出了什么问题吗?

检查后,在指定veterinary_care和pet_store时,附近搜索似乎返回"ZERO_RESULTS",因为您所在的位置附近没有开放的宠物店和兽医诊所。请注意,标记为永久/临时关闭的场所不会出现在场所搜索[1](例如附近搜索(结果中。您可以通过场所详细信息[2]验证场所是暂时关闭还是永久关闭(如果permanntly_closed字段为true(。

你可以使用某个地点附近的一家已知的开放宠物店来检查这种行为。您可以为附近搜索请求提供特定位置。测试时可以尝试以下示例。

相关内容

  • 没有找到相关文章