我使用 Google place Api,但是当在银行和餐厅等搜索地点附近使用时……这行不通?
Posted
技术标签:
【中文标题】我使用 Google place Api,但是当在银行和餐厅等搜索地点附近使用时……这行不通?【英文标题】:i use Google place Api but when use near search place like bank & restaurant & .. this not work? 【发布时间】:2016-01-20 02:38:33 【问题描述】:1.i 为 android 启用 android google map android api 和 google places Api
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" />
谷歌地方活动:
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
我找不到附近的地方:(
【问题讨论】:
【参考方案1】:试试这个。
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" />
【讨论】:
wptrafficanalyzer.in/blog/… 使用这个 此链接wptrafficanalyzer.in/blog/… 很有用..................谢谢您,Verma 先生以上是关于我使用 Google place Api,但是当在银行和餐厅等搜索地点附近使用时……这行不通?的主要内容,如果未能解决你的问题,请参考以下文章
需要一个类似于 Yelp 和 Google Places 的良好商业搜索 API
获取与 Google Places/Geocoding API 的交集
Google Places API Autocomplete 仅获取城市列表
Google Places Api iOS Daily Limit for Unauthenticated Use Exceeded 错误