简体   繁体   English

我使用Google Place Api,但是在附近的搜索地点(如银行和餐厅&..)使用时,这不起作用?

[英]i use Google place Api but when use near search place like bank & restaurant & .. this not work?

1.i enable android google map android api and google places Api for android 1.i启用android google map android api和google place api for android

2.my google map is worked but when use Search place thats Not Work 2.我的谷歌地图是可行的,但是在使用搜索位置时那是行不通的

this my code please help me 这我的代码请帮助我

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
}

} i cant find nearshearch place :( 我找不到Nearshearch的地方:(

try this. 尝试这个。

< <

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" />

instead of 代替

<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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM