nearbySearch method
Future<Response<PlacesNearbySearchResponse> >
nearbySearch({
- required String location,
- String? keyword,
- String? maxprice,
- String? minprice,
- String? name,
- bool? opennow,
- String? pagetoken,
- String? rankby,
- num? radius,
- String? type,
- String? language = 'en',
- CancelToken? cancelToken,
- Map<
String, dynamic> ? headers, - Map<
String, dynamic> ? extra, - ValidateStatus? validateStatus,
- ProgressCallback? onSendProgress,
- ProgressCallback? onReceiveProgress,
nearbySearch A Nearby Search lets you search for places within a specified area. You can refine your search request by supplying keywords or specifying the type of place you are searching for.
Parameters:
location
- The point around which to retrieve place information. This must be specified aslatitude,longitude
.keyword
- A term to be matched against all content that Google has indexed for this place, including but not limited to name and type, as well as customer reviews and other third-party content. Note that explicitly including location information using this parameter may conflict with the location, radius, and rankby parameters, causing unexpected results.maxprice
- Restricts results to only those places within the specified range. Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. The exact amount indicated by a specific value will vary from region to region.minprice
- Restricts results to only those places within the specified range. Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. The exact amount indicated by a specific value will vary from region to region.name
- Not Recommended A term to be matched against all content that Google has indexed for this place. Equivalent tokeyword
. Thename
field is no longer restricted to place names. Values in this field are combined with values in the keyword field and passed as part of the same search string. We recommend using only thekeyword
parameter for all search terms.opennow
- Returns only those places that are open for business at the time the query is sent. Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query.pagetoken
- Returns up to 20 results from a previously run search. Setting apagetoken
parameter will execute a search with the same parameters used previously — all parameters other than pagetoken will be ignored.rankby
- Specifies the order in which results are listed. Possible values are: -prominence
(default). This option sorts results based on their importance. Ranking will favor prominent places within the set radius over nearby places that match but that are less prominent. Prominence can be affected by a place's ranking in Google's index, global popularity, and other factors. When prominence is specified, theradius
parameter is required. -distance
. This option biases search results in ascending order by their distance from the specified location. Whendistance
is specified, one or more ofkeyword
,name
, ortype
is required.radius
- Defines the distance (in meters) within which to return place results. You may bias results to a specified circle by passing alocation
and aradius
parameter. Doing so instructs the Places service to prefer showing results within that circle; results outside of the defined area may still be displayed. The radius will automatically be clamped to a maximum value depending on the type of search and other parameters. * Autocomplete: 50,000 meters * Nearby Search: * withkeyword
orname
: 50,000 meters * withoutkeyword
orname
*rankby=prominence
(default): 50,000 meters *rankby=distance
: A few kilometers depending on density of area * Query Autocomplete: 50,000 meters * Text Search: 50,000 meterstype
- Restricts the results to places matching the specified type. Only one type may be specified. If more than one type is provided, all types following the first entry are ignored. *type=hospital|pharmacy|doctor
becomestype=hospital
*type=hospital,pharmacy,doctor
is ignored entirely See the list of supported types. <div class="note">Note: Adding bothkeyword
andtype
with the same value (keyword=cafe&type=cafe
orkeyword=parking&type=parking
) can yieldZERO_RESULTS
.language
- The language in which to return results. * See the list of supported languages. Google often updates the supported languages, so this list may not be exhaustive. * Iflanguage
is not supplied, the API attempts to use the preferred language as specified in theAccept-Language
header. * The API does its best to provide a street address that is readable for both the user and locals. To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user if necessary, observing the preferred language. All other addresses are returned in the preferred language. Address components are all returned in the same language, which is chosen from the first component. * If a name is not available in the preferred language, the API uses the closest match. * The preferred language has a small influence on the set of results that the API chooses to return, and the order in which they are returned. The geocoder interprets abbreviations differently depending on language, such as the abbreviations for street types, or synonyms that may be valid in one language but not in another. For example, utca and tér are synonyms for street in Hungarian.cancelToken
- ACancelToken
that can be used to cancel the operationheaders
- Can be used to add additional headers to the requestextras
- Can be used to add flags to the requestvalidateStatus
- AValidateStatus
callback that can be used to determine request success based on the HTTP status of the responseonSendProgress
- AProgressCallback
that can be used to get the send progressonReceiveProgress
- AProgressCallback
that can be used to get the receive progress
Returns a Future containing a Response
with a PlacesNearbySearchResponse as data
Throws DioError
if API call or serialization fails
Implementation
Future<Response<PlacesNearbySearchResponse>> nearbySearch({
required String location,
String? keyword,
String? maxprice,
String? minprice,
String? name,
bool? opennow,
String? pagetoken,
String? rankby,
num? radius,
String? type,
String? language = 'en',
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path = r'/maps/api/place/nearbysearch/json';
final _options = Options(
method: r'GET',
headers: <String, dynamic>{
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[
{
'type': 'apiKey',
'name': 'ApiKeyAuth',
'keyName': 'key',
'where': 'query',
},
],
...?extra,
},
validateStatus: validateStatus,
);
final _queryParameters = <String, dynamic>{
if (keyword != null)
r'keyword':
encodeQueryParameter(_serializers, keyword, const FullType(String)),
r'location':
encodeQueryParameter(_serializers, location, const FullType(String)),
if (maxprice != null)
r'maxprice': encodeQueryParameter(
_serializers, maxprice, const FullType(String)),
if (minprice != null)
r'minprice': encodeQueryParameter(
_serializers, minprice, const FullType(String)),
if (name != null)
r'name':
encodeQueryParameter(_serializers, name, const FullType(String)),
if (opennow != null)
r'opennow':
encodeQueryParameter(_serializers, opennow, const FullType(bool)),
if (pagetoken != null)
r'pagetoken': encodeQueryParameter(
_serializers, pagetoken, const FullType(String)),
if (rankby != null)
r'rankby':
encodeQueryParameter(_serializers, rankby, const FullType(String)),
if (radius != null)
r'radius':
encodeQueryParameter(_serializers, radius, const FullType(num)),
if (type != null)
r'type':
encodeQueryParameter(_serializers, type, const FullType(String)),
if (language != null)
r'language': encodeQueryParameter(
_serializers, language, const FullType(String)),
};
final _response = await _dio.request<Object>(
_path,
options: _options,
queryParameters: _queryParameters,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
PlacesNearbySearchResponse _responseData;
try {
const _responseType = FullType(PlacesNearbySearchResponse);
_responseData = _serializers.deserialize(
_response.data!,
specifiedType: _responseType,
) as PlacesNearbySearchResponse;
} catch (error, stackTrace) {
throw DioError(
requestOptions: _response.requestOptions,
response: _response,
type: DioErrorType.other,
error: error,
)..stackTrace = stackTrace;
}
return Response<PlacesNearbySearchResponse>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}