0

我想致电 service.textSearch 以获取一个机构的地址、电话和营业时间。我知道该机构的名称及其 google plus ID。

var testName = "";
var latitude = $("#googleID").attr('data-lat');
var longitude = $("#googleID").attr('data-long');
var centerTown = new google.maps.LatLng(latitude,longitude);
var service = '';
var service1 = '';
var map_google = new google.maps.Map(document.getElementById('map_google'), {
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: centerTown,
      zoom: 5
    });


/*GOOGLE PLUS AFFICHAGE AGENCE LOCAL*/  
if ($.cookie("agenceDemande") != '')
{

    var idPlus = $("#googleID").attr('value');
    var config = {
        client_id: 'clientId',
        immediate: true
      };
      gapi.client.setApiKey('APIKEY');
      gapi.client.load('plus', 'v1', function() {
        var request = gapi.client.plus.activities.list({
            'userId': idPlus,
            'maxResults': '20',
            'collection': 'public'
        });

        var personReq = gapi.client.plus.people.get({'userId': idPlus});
    personReq.execute(function(data) {
      testName = data.displayName;
      $("#nomAgence").html('<h2>'+testName+'</h2>');
      initialize();

    });

  });
}




function initialize() 
{

  var request = {
    location: centerTown,
    radius: '3000',
    query: testName
  };

  service = new google.maps.places.PlacesService(map_google);

  service.textSearch(request, callback);

}

function callback(results, status) 
{
    if (status == google.maps.places.PlacesServiceStatus.OK) 
    {

        for (var i = 0; i < results.length; i++) 
        {
                var place = results[i];
                if (results[i].name == testName)
                {
                    var request1 = {
                        reference: results[i].reference
                    };

                    service1 = new google.maps.places.PlacesService(map_google);
                    service1.getDetails(request1, callbackDetails);

                }
        }
    }
    else
    {
        alert("Doesn't Work");
    }
}


function callbackDetails(place, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {

    $('#adresseAgence').html(place.formatted_address);
    $('#phone').html(place.formatted_phone_number);
    // alert(place.opening_hours);

    if (place.opening_hours != 'undefined' && place.opening_hours != null && place.opening_hours != '') 
    {
        $('#horairesAgence').html("Horaires d'ouverture de l'agence");
        $.each(place.opening_hours.periods,function(key,value){
            var jour = '';
            switch (value.open.day) {
                case 1: jour = 'Lundi'; break;
                case 2: jour = 'Mardi'; break;
                case 3: jour = 'Mercredi'; break;
                case 4: jour = 'Jeudi'; break; 
                case 5: jour = 'Vendredi'; break;   
                case 6: jour = 'Samedi'; break; 
                case 7: jour = 'Dimanche'; break;
            }
             $('#horairesAgence').html($('#horairesAgence').html()+'</br>'+jour+': '+value.open.time.substr(0,2)+'h'+value.open.time.substr(-2)+'-'+value.close.time.substr(0,2)+'h'+value.close.time.substr(-2)+'</br>');
        });
    }
    else 
    {

        $('#horairesAgence').html('Horaires non renseignés');

    }



  }
}

我在本地尝试了这段代码,它工作得很好,但在网上我只有代理的名称和 google plus api。

问候

4

0 回答 0