Assign google 将详细信息放入 php 变量
Assign google places details into php variable
我正在使用 google 个地方 api 来获取一些业务详细信息。我查看了 google 并找到了在 google 地图上显示详细信息的方法。我还想实现的是将细节分配给 php 变量。下面的代码显示了地图上的详细信息;
<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>
我希望能够实现的是例如下面的代码;
<script>
var a="Hello";
</script>
<?php
echo $variable = "<script>document.write(a)</script>";
?>
总而言之,我希望 google 将参数分配给 php avriables,这样我就可以随心所欲地使用它们。
提前致谢
四处寻找后,我以不同的方式找到了答案。对于在某些时候可能需要它的任何人/这是下面的代码
$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'];
希望对您有所帮助
我正在使用 google 个地方 api 来获取一些业务详细信息。我查看了 google 并找到了在 google 地图上显示详细信息的方法。我还想实现的是将细节分配给 php 变量。下面的代码显示了地图上的详细信息;
<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>
我希望能够实现的是例如下面的代码;
<script>
var a="Hello";
</script>
<?php
echo $variable = "<script>document.write(a)</script>";
?>
总而言之,我希望 google 将参数分配给 php avriables,这样我就可以随心所欲地使用它们。
提前致谢
四处寻找后,我以不同的方式找到了答案。对于在某些时候可能需要它的任何人/这是下面的代码
$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'];
希望对您有所帮助