Я запрашиваю данные Google Мест на карте с заполненным параметром "fields", как в примере с Google: https://developers.google.com/places/web-service/details#fields Я запрашиваю только 3 поля: geometry, name, vicinity
.
Вв документации четко указано, что вы должны предоставить хотя бы 1 поле: https://developers.google.com/places/web-service/details#fields
function requestGooglePlaces(placeType) {
var request = {
fields: ['name', 'geometry', 'vicinity'],
location: location,
radius: '5000',
type: [placeType],
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
});
google.maps.event.addListener(marker, 'click', function () {
console.log(place);
var contentInfoWindows = (place.name + "<br>" + place.vicinity + "<br>" + place.geometry.location);
});
В моей консоли вывода Javascript я получаю слишком много полей:
{geometry: {…}, icon: "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png", id: "5ffe179c6015e35e796ff313a35ff5149efd396d", name: "Carrefour market", opening_hours: {…}, …}
geometry: {location: _.Q, viewport: _.R}
html_attributions: []
icon: "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png"
id: "5ffe179c6015e35e796ff6f3a35ff5149efd396d"
name: "Carrefour market"
opening_hours:
open_now: false
__proto__: Object
photos: Array(1)
0: {height: 4128, html_attributions: Array(1), width: 2322, getUrl: ƒ}
length: 1
__proto__: Array(0)
place_id: "ChIJx3_zP3I8w0cR5i6Q99tFeCU"
plus_code: {compound_code: "V84J+X6 Harelbeke, Belgium", global_code: "9F25V84J+X6"}
rating: 4.4
reference: "ChIJx3_zP3I8w0cR5i6Q99tFeCU"
scope: "GOOGLE"
types: (7) ["supermarket", "bakery", "grocery_or_supermarket", "store", "point_of_interest", "food", "establishment"]
user_ratings_total: 22
vicinity: "Mainstreet 137, NY"
__proto__: Object