Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用常规搜索谷歌api进行改进_Android_Kotlin_Google Api_Retrofit_Google Search Api - Fatal编程技术网

Android 使用常规搜索谷歌api进行改进

Android 使用常规搜索谷歌api进行改进,android,kotlin,google-api,retrofit,google-search-api,Android,Kotlin,Google Api,Retrofit,Google Search Api,我有电话服务 interface ApiService { @GET("customsearch/v1") fun getTopResult( @Query(QUERY_PARAM_API_KEY) key: String = "AIzaSyFhdJHf....7IlRcE", @Query(QUERY_PARAM_CX) cx: String = "017576662512468239146:omuauf_lfve", @Quer

我有电话服务

interface ApiService {
    @GET("customsearch/v1")
    fun getTopResult(
        @Query(QUERY_PARAM_API_KEY) key: String = "AIzaSyFhdJHf....7IlRcE",
        @Query(QUERY_PARAM_CX) cx: String = "017576662512468239146:omuauf_lfve",
        @Query(QUERY_PARAM_QUERY) q: String
    ) : Single<ResultInfoList>

    companion object {
        private const val QUERY_PARAM_API_KEY = "key"
        private const val QUERY_PARAM_CX = "cx"
        private const val QUERY_PARAM_QUERY = "q"
    }

}
我试图通过调用 ApiFactory.apiService.getTopResult(q=“something”)

但这款应用程序在网上很受欢迎

.baseUrl(基本URL)

任何帮助都将不胜感激

我已经在我的一个项目中成功地实现了GooglePlaces搜索API。以下是实施守则: APISERVICE:- @获取(“api/place/nearbysearch/json?&key=GOOGLE\u place\u api\u key”) 调用getNearbyCall(@Query(“您的查询类型”)字符串类型,@Query(“纬度经度”) 字符串位置,@Query(“半径单位为米”)int RADIUS)

客户机:-

    if (retrofit == null) {
        retrofit = new Retrofit.Builder()
                .baseUrl("https://maps.googleapis.com/maps/")
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
private void doRequestForGooglePlaceApi(double latitude, double longitude, int locationRadius, String locationType) {
        APIService mApiService = RetrofitClient.getClient("https://maps.googleapis.com/maps/").create(APIService.class);

        Call<NearbyModel> call = mApiService.getNearbyCall(locationType, latitude + "," + longitude, locationRadius);

        call.enqueue(new Callback<NearbyModel>() {
            @Override
            public void onResponse(Call<NearbyModel> call, Response<NearbyModel> response) {
                if (response.isSuccessful() && response.body() != null && response.body().getResults() != null) {
                    setNearbyAdapter(response.body().getResults());
                } else {
                    Globals.showToast(NearbyActivity.this, getString(R.string.msg_something_went_wrong));
                }
            }

            @Override
            public void onFailure(Call<NearbyModel> call, Throwable t) {
                Globals.showToast(NearbyActivity.this, getString(R.string.msg_something_went_wrong));
            }
        });

    }
和我的最后一个API调用:-

    if (retrofit == null) {
        retrofit = new Retrofit.Builder()
                .baseUrl("https://maps.googleapis.com/maps/")
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
private void doRequestForGooglePlaceApi(double latitude, double longitude, int locationRadius, String locationType) {
        APIService mApiService = RetrofitClient.getClient("https://maps.googleapis.com/maps/").create(APIService.class);

        Call<NearbyModel> call = mApiService.getNearbyCall(locationType, latitude + "," + longitude, locationRadius);

        call.enqueue(new Callback<NearbyModel>() {
            @Override
            public void onResponse(Call<NearbyModel> call, Response<NearbyModel> response) {
                if (response.isSuccessful() && response.body() != null && response.body().getResults() != null) {
                    setNearbyAdapter(response.body().getResults());
                } else {
                    Globals.showToast(NearbyActivity.this, getString(R.string.msg_something_went_wrong));
                }
            }

            @Override
            public void onFailure(Call<NearbyModel> call, Throwable t) {
                Globals.showToast(NearbyActivity.this, getString(R.string.msg_something_went_wrong));
            }
        });

    }
专用void doRequestForGooglePlaceApi(双纬度、双经度、int-locationRadius、String-locationType){
APIService mApiService=客户端。getClient(“https://maps.googleapis.com/maps/)创建(APIService.class);
Call Call=mApiService.getNearbyCall(位置类型,纬度+,“+经度,位置半径);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()&&response.body()!=null&&response.body().getResults()!=null){
setNearbyAdapter(response.body().getResults());
}否则{
showtoos(NearbyActivity.this,getString(R.string.msg_something_出错));
}
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
showtoos(NearbyActivity.this,getString(R.string.msg_something_出错));
}
});
}

您可以发布您的错误吗log@Deepakjava.lang.IllegalStateException:无法执行方法。在com.example.googlesearchapp.api.apifacture.(apifacture.kt:12)上,我询问了谷歌的常规搜索