【问题标题】:i use Google place Api but when use near search place like bank & restaurant & .. this not work?我使用 Google place Api,但是当在银行和餐厅等搜索地点附近使用时……这行不通?
【发布时间】: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
}

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

【问题讨论】:

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


    【解决方案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" />
    

    【讨论】:

    猜你喜欢
    • 2020-11-02
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多