android-GeoDataApi.getAutocompletePredictions()中LatLngBounds的用途是什么?

android-GeoDataApi.getAutocompletePredictions()中LatLngBounds的用途是什么?,第1张

概述GooglePlacesAutocompleteAPI中使用的LatLngBounds对象是什么?..和/或它的意思是:biasingtheresultstoaspecificareaspecifiedbylatitudeandlongitudebounds?在Google地方信息自动填充文档中,它表示要传入LatLngBounds和AutocompleteFilter.PendingResult<Aut

Google Places autocomplete API中使用的LatLngBounds对象是什么?

..和/或它的意思是:

biasing the results to a specific area specifIEd by latitude and longitude bounds

在Google地方信息自动填充文档中,它表示要传入LatLngBounds和autocompleteFilter.

PendingResult<autocompletePredictionBuffer> result =    Places.GeoDataAPI.getautocompletePredictions(        mGoogleapiclient, query, bounds, autocompleteFilter);

在使用“地方信息自动填充”功能后,我可以看到autocompleteFilter如何限制结果(例如按国家/地区).还不清楚如何使用LatLngBounds.在示例代码中,Bounds对象具有以下内容:

private static final LatLngBounds BOUNDS_MOUNTAIN_VIEW =                     new LatLngBounds(                    new LatLng(37.398160, -122.180831),                     new LatLng(37.430610, -121.972090));

它说的范围是Mountain VIEw(加利福尼亚州旧金山湾区的一个城市),但是当filter为null时,我仍然可以获得其他国家/地区的结果.

从此资源:
https://developers.google.com/places/android-api/autocomplete

Your app can get a List of predicted place names and/or addresses from the autocomplete service by calling GeoDataAPI.getautocompletePredictions(), passing the following parameters:

required: A LatLngBounds object, biasing the results to a specific area specifIEd by latitude and longitude bounds.

Optional: An autocompleteFilter containing a set of place types, which you can use to restrict the results to one or more types of place.

解决方法:

假设您要搜索Cafe The Coffee Day,如果您设置LatLngBounds,则结果将根据该位置显示.

例如,如果您在纽约设置LatLngBounds并搜索“咖啡馆咖啡日”,则会看到纽约的结果.如果设置悉尼的LatLngBounds,您将看到悉尼的结果.

现在,如果要将LatLngBounds设置为您的位置,则必须获取当前位置并根据该位置设置LatLngBounds.

您也可以指定半径以获得特定结果.

例如.

我正在使用下面的代码来获取当前城市的结果.

protected Googleapiclient mGoogleapiclient;private PlaceautocompleteAdapter mAdapter;autoCompleteTextVIEw autoTextVIEwPlace;mGoogleapiclient = new Googleapiclient.Builder(getActivity())                .addAPI(Places.GEO_DATA_API)                .build();// I am getting Latitude and Longitude From Web APIif((strLatitude != null && !strLatitude.trim().isEmpty()) && (strLongitude != null && !strLongitude.trim().isEmpty())){        LatLng currentLatLng = new LatLng(Double.parseDouble(strLatitude), Double.parseDouble(strLongitude));        if(currentLatLng != null){                setLatlngBounds(currentLatLng);        }}public voID setLatlngBounds(LatLng center){        double radiusdegrees = 0.10;        LatLng northEast = new LatLng(center.latitude + radiusdegrees, center.longitude + radiusdegrees);        LatLng southWest = new LatLng(center.latitude - radiusdegrees, center.longitude - radiusdegrees);        LatLngBounds bounds = LatLngBounds.builder().include(northEast).include(southWest).build();        mAdapter = new PlaceautocompleteAdapter(getActivity(), mGoogleapiclient, bounds,                null);        autoTextVIEwPlace.setAdapter(mAdapter);    }
总结

以上是内存溢出为你收集整理的android-GeoDataApi.getAutocompletePredictions()中LatLngBounds的用途是什么?全部内容,希望文章能够帮你解决android-GeoDataApi.getAutocompletePredictions()中LatLngBounds的用途是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1091161.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存