job*_*ert 10 android google-maps google-places-api google-places google-places-autocomplete
目前,我正在构建一个功能来搜索具有AutocompleteTextView的公司.要实现这一点,我使用一个PlaceAutocomplete IntentBuilder和叠加模式,如下所示:
try {
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_ESTABLISHMENT)
.setCountry("NL")
.build();
Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
.setFilter(typeFilter)
.build(activity);
activity.startActivityForResult(intent, placeAutocompleteRequestCode);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
Log.e(TAG, "Something went wrong getting the places fragment." + e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
我收到这样的地方:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place place = PlaceAutocomplete.getPlace(this, data);
Log.i(TAG, "Place: " + place.getName());
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(this, data);
Log.i(TAG, status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
// The user canceled the operation.
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我找不到'地方'对象的开放时间.我怎么能找回它们?我只能找到使用API的其他人,但我更喜欢这个自动完成片段.
还尝试使用API调用以便稍后按地点ID获取地点详细信息,但似乎只允许服务器密钥.如果有人在Android上使用发布密钥,那么它现在是一个不错的修补程序.但仍然感觉很麻烦.
请使用下面的代码:
private class ParserTask extends AsyncTask<String, Integer, HashMap<String,String>>{
JSONObject jObject;
@Override
protected HashMap<String,String> doInBackground(String... jsonData) {
HashMap<String, String> hPlaceDetails = null;
PlaceDetailsJSONParser placeDetailsJsonParser = new PlaceDetailsJSONParser();
try{
// this object give JSON
jObject = new JSONObject(jsonData[0]);
// this object give Result
JSONObject jresult = new JSONObject(jObject[1]);
// this object give opening_hours
JSONObject jopening_hours = new JSONObject(jresult[2]);
// this object give periods
JSONObject jperiods = new JSONObject(jopening_hours[2]);
}catch(Exception e){
Log.d("Exception",e.toString());
}
return jperiods;
}
// Executed after the complete execution of doInBackground() method
@Override
protected void onPostExecute(JsonObject periods){
HashMap<String,String> periods;
// put your condition
for(..)
{
JsonObject day = new JSONObject(periods[i]);
periods.put("key",day.get("day"));
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
526 次 |
最近记录: |