Ahm*_*sam 7 android google-maps google-places-api google-places
当我尝试在“地点自动完成”中搜索时,出现“无法加载搜索结果” 并且日志显示
“自动填充时出错:OVER_QUERY_LIMIT”
我已启用https://console.cloud.google.com/, 并且API密钥运行良好。
Java代码
String apiKey = "MY API KEY";
private RadioGroup mRadioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_costumer_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
Places.initialize(getApplicationContext(), apiKey);
PlacesClient placesClient = Places.createClient(this);
// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
getSupportFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
// Specify the types of place data to return.
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
destination = place.getName().toString();
destinationLatLng = place.getLatLng();
Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
}
@Override
public void onError(Status status) {
Log.e(TAG, "onError: " + status);
}
});
Run Code Online (Sandbox Code Playgroud)
XML代码
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:layout_margin="20sp">
<fragment
android:id="@+id/place_autocomplete_fragment"
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6024 次 |
| 最近记录: |