B
B
burguy832019-06-07 13:53:16
Google Maps
burguy83, 2019-06-07 13:53:16

How to pass place_id to service.getDetails in google maps api?

I want to pull the details of the organization, namely contacts and testimonials. To do this, you need to get the place_id and pass it to service.getDetails. Place_id I found how to get it, but I don’t know how to pass it in js.

var map;
      var service;
      var infowindow;
      var marker;

      function initMap() {

        map = new google.maps.Map(
            document.getElementById('map'), {zoom: 15});

        var request = {
          query: '<?php echo $content['company']['domicilios']['razon_social'];?>,+<?php echo $content['company']['domicilios']['calle'];?>,+<?php echo $content['company']['domicilios']['numero'];?>+<?php echo $content['company']['domicilios']['localidad'];?>+<?php echo $content['company']['domicilios']['provincia'];?>+<?php echo $content['company']['domicilios']['codigo_postal'];?>',
          fields: ['name', 'geometry'],
        };
        console.log(request);

        service = new google.maps.places.PlacesService(map);
          service.textSearch(request,  callback);

        service.findPlaceFromQuery(request, function(results, status) {
          if (status === google.maps.places.PlacesServiceStatus.OK) {
            for (var i = 0; i < results.length; i++) {
              createMarker(results[i]);
            }

            map.setCenter(results[0].geometry.location);
          }
        });

          // Checks that the PlacesServiceStatus is OK, and adds a marker
          // using the place ID and location from the PlacesService.
          function callback(results,  status)  {
              if (status == google.maps.places.PlacesServiceStatus.OK)  {
                  var marker =  new google.maps.Marker({
                      map:  map,
                      place:  {
                          placeId:  results[ 0 ].place_id,  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<здесь лежит place_id
                          location:  results[ 0].geometry.location,

                      }
                  });

              }

          }

          function createMarker(place) {
              var marker = new google.maps.Marker({
                  map: map,
                  position: place.geometry.location
              });

          }

      }

    </script>

And you need to send it here:
var request = {
          placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4',     <<<<<<<<<<<<<<<<<<как сюда передать содержимое этой переменной placeId:  results[ 0 ].place_id
          fields: ['name', 'formatted_address', 'place_id', 'geometry']
        };

        var infowindow = new google.maps.InfoWindow();
        var service = new google.maps.places.PlacesService(map);

        service.getDetails(request, function(place, status) {
          if (status === google.maps.places.PlacesServiceStatus.OK) {
            var marker = new google.maps.Marker({
              map: map,
              position: place.geometry.location
            });
            google.maps.event.addListener(marker, 'click', function() {
              infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
                'Place ID: ' + place.place_id + '<br>' +
                place.formatted_address + '</div>');
              infowindow.open(map, this);
            });
          }
        });

Подскажите как это осуществляется в js.
Может у кого то есть реализация вывода доп инфы о компании на рабочем примере?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question