2017-11-12 2 views
2

Ich benutze Google Orte API, um einige geschäftliche Details zu erhalten. Ich habe Google angeschaut und finde den Weg, um die Details auf Google Maps anzuzeigen. Was ich auch erreichen möchte, ist die Zuordnung der Details zu PHP-Variablen. Unterhalb des Codes werden die Details auf der Karte angezeigt.Zuweisen von Google-Orte Details in PHP Variable

<script> 
     // This example requires the Places library. Include the libraries=places 
     // parameter when you first load the API. For example: 
     // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"> 

     function initMap() { 
     var map = new google.maps.Map(document.getElementById('map'), { 
      center: {lat: -9999.9999, lng: 99999.99999}, 
      zoom: 1 
     }); 

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

     service.getDetails({ 
      placeId: 'XXXXXXXXXX' 
     }, 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>' + 
       'Telephone: ' + place.formatted_phone_number + '<br>' + 
       'Website: ' + place.website + '<br>' + 
       place.formatted_address + '</div>'); 
       infowindow.open(map, this); 
      }); 
      } 
     }); 
     } 
    </script> 


<div id="map"></div> 
<script async defer 
src="https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXXXXXX&libraries=places&callback=initMap"> 
</script> 

Was ich erreichen möchte, ist wie der Code unten zum Beispiel;

<script> 
    var a="Hello"; 
</script> 
<?php 
    echo $variable = "<script>document.write(a)</script>"; 
?> 

So zusammenzufassen, möchte ich PHP zugewiesen Orte Parameter google werden avriables, so kann ich sie jede mögliche Weise möchte ich nutzen.

Vielen Dank im Voraus

Antwort

0

Nachdem sich suchend, fand ich die Antwort auf eine andere Weise. Für alle, die es irgendwann brauchen/Hier ist der Code unter

$url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=PLACE_ID&key=API_KEY'; 
$json = file_get_contents($url); 
$jsonContent = json_decode($json, TRUE); 
$jsonContent['result']['name']; 
$jsonContent['result']['formatted_phone_number']; 
$jsonContent['result']['formatted_address']; 
$jsonContent['result']['website']; 

Hoffe, es hilft