admin管理员组文章数量:1387360
I am referring to Nearby Search (New).
Every request requires a Field Mask set outside of the request proto.
- Could you explain how do I set this header with searchNearby using v1.PlacesClient?
- Is there a way to use @googlemaps/google-maps-services-js instead of v1.PlacesClient? I've tried this library using
import {Client} from @googlemaps/google-maps-services-js
, but it always calls the legacy Nearby Search. - Does it make sense to use v1.PlacesClient with backend/server-side applications or only with frontend applications?
Here is my code snippet:
// Import the Places library
import places from '@googlemaps/places';
// Instantiate a client
const placesClient = new places.v1.PlacesClient(
{
apiKey: process.env.GOOGLE_MAPS_API_KEY!
}
);
const requestParams = {
locationRestriction: {
circle: {
center: {
latitude: 48.1351253,
longitude: 11.5819806,
},
},
radius: 3000,
},
includedTypes: ['restaurant'], // restrict the results to places matching the specified type.
language: 'en', // specify the language of the response.
maxResultCount: 20, // maximum number of results to return.
};
const requestOptions = { timeout: 1000 }
const placesNearbyResponse = await placesClient.searchNearby(requestParams, requestOptions);
I am referring to Nearby Search (New).
Every request requires a Field Mask set outside of the request proto.
- Could you explain how do I set this header with searchNearby using v1.PlacesClient?
- Is there a way to use @googlemaps/google-maps-services-js instead of v1.PlacesClient? I've tried this library using
import {Client} from @googlemaps/google-maps-services-js
, but it always calls the legacy Nearby Search. - Does it make sense to use v1.PlacesClient with backend/server-side applications or only with frontend applications?
Here is my code snippet:
// Import the Places library
import places from '@googlemaps/places';
// Instantiate a client
const placesClient = new places.v1.PlacesClient(
{
apiKey: process.env.GOOGLE_MAPS_API_KEY!
}
);
const requestParams = {
locationRestriction: {
circle: {
center: {
latitude: 48.1351253,
longitude: 11.5819806,
},
},
radius: 3000,
},
includedTypes: ['restaurant'], // restrict the results to places matching the specified type.
language: 'en', // specify the language of the response.
maxResultCount: 20, // maximum number of results to return.
};
const requestOptions = { timeout: 1000 }
const placesNearbyResponse = await placesClient.searchNearby(requestParams, requestOptions);
Share
Improve this question
asked Mar 17 at 14:54
NirNir
1132 silver badges6 bronze badges
1 Answer
Reset to default 1The documentation is a bit lacking but I found the correct info here: https://www.npmjs/package/@googlemaps/places
const placesNearbyResponse = await placesClient.searchNearby(requestParams, {
otherArgs: {
headers: {
"X-Goog-FieldMask": "places.displayName",
},
},
});
I would not recommend to use @googlemaps/google-maps-services-js since it uses the legacy API's for now.
v1.PlacesClient is meant more for backend, the way you configured it I think it would use gRPC. For the Frontend the REST API is the more regular choice. https://developers.google/maps/documentation/javascript/nearby-search#javascript
本文标签: nodejsHow to include FieldMask in Nearby Search (New)Stack Overflow
版权声明:本文标题:node.js - How to include FieldMask in Nearby Search (New)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744552931a2612294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论