我使用谷歌的地方Api,但在银行和附近的搜索地点附近使用餐厅& ..这不行吗?

时间:2015-10-21 07:38:49

标签: java android eclipse google-maps google-api

1.i启用Android谷歌地图android api和谷歌地方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
}

} 我找不到近处的地方:(

1 个答案:

答案 0 :(得分:0)

试试这个。

&LT;

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