gpt4 book ai didi

java - 我使用 Google place Api,但是当在银行和餐厅等搜索地点附近使用时,这不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 13:19:17 24 4
gpt4 key购买 nike

1.i 启用 Android 谷歌地图 Android API 和 Google Places Api for Android

2.我的谷歌地图可以工作,但是当使用搜索地点时就不行了

这是我的代码,请帮助我

manifest:

<uses-sdk android:minSdkVersion="7" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="6" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my API_KEY" />

google place avtivity :

public class GooglePlacesActivity extends FragmentActivity implements LocationListener {

private static final String GOOGLE_API_KEY = "my api key";
GoogleMap googleMap;
EditText placeText;
double latitude = 0;
double longitude = 0;
private int PROXIMITY_RADIUS = 5000;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//show error dialog if GoolglePlayServices not available
if ( !isGooglePlayServicesAvailable()) {
finish();
}
setContentView(R.layout.activity_google_places);

placeText = (EditText) findViewById(R.id.placeText);
Button btnFind = (Button) findViewById(R.id.btnFind);
SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
googleMap = fragment.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);
if (location != null) {
onLocationChanged(location);
}
locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);

btnFind.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
String type = placeText.getText().toString();
StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
googlePlacesUrl.append("location=" + latitude + "," + longitude);
googlePlacesUrl.append("&radius=" + PROXIMITY_RADIUS);
googlePlacesUrl.append("&types=" + "hospital");
googlePlacesUrl.append("&sensor=true");
googlePlacesUrl.append("&key=" + GOOGLE_API_KEY);

GooglePlacesReadTask googlePlacesReadTask = new GooglePlacesReadTask();
Object[] toPass = new Object[2];
toPass[0] = googleMap;
toPass[1] = googlePlacesUrl.toString();
googlePlacesReadTask.execute(toPass);
}
});
}


private boolean isGooglePlayServicesAvailable() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (ConnectionResult.SUCCESS == status) {
return true;
} else {
GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
return false;
}
}


public void onLocationChanged(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(12));
}


public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}


public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}


public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}

}我找不到附近的搜索地点:(

最佳答案

试试这个。

<

meta-data android:name="com.google.android.geo.API_KEY"
android:value="YOUR API KEY"/>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

而不是

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="6" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my API_KEY" />

关于java - 我使用 Google place Api,但是当在银行和餐厅等搜索地点附近使用时,这不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33253550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com